Found 26504 Articles for Server Side Programming

Golang program to reverse a string using stacks

Akhil Sharma
Updated on 20-Feb-2023 10:49:36

512 Views

In this article, we will see how to reverse a string using stacks with Go Programming. A stack is a Last In First Out (LIFO) compliant data structure in Go. This implies that the first element to be eliminated will be the one that was most recently added to the stack. A doubly-linked list is implemented in the built-in Go package "container/list" and can be used to build a stack. Slices (dynamic arrays) are frequently used to implement stacks in Go, though. Let’s see how it’s executed using different set of examples. Method 1: Converting the string to slice of ... Read More

Golang program to show use of super keyword in class

Akhil Sharma
Updated on 20-Feb-2023 10:43:58

1K+ Views

In golang, the "super" term doesn't exist in Go. The "super" keyword is used in object-oriented programming languages to denote the parent class or the class that is being inherited from. It is often used to access parent class methods or properties that the child class has modified. In this article, we will see how to use super keyword in the class with different examples. Method 1: Using child struct and parent struct In this Method, we will learn how to use super keyword in class using child struct and parent struct. Here, a Parent struct is embedded in the ... Read More

Golang program to remove all whitespaces from a string

Akhil Sharma
Updated on 20-Feb-2023 10:47:10

6K+ Views

When we remove whitespaces from a string it means removing blank spaces, tabs, and other white space characters, including newline characters. This can be helpful for parsing user input or working with data in a particular format, among other instances where we wish to clean up or standardize a string before processing it further. There are various ways to eliminate whitespace from a string. A few examples include: Using the TrimSpace function, whitespace characters at the beginning and end of a string are eliminated. Using the Replace function to replace any whitespace in the string with a string that is ... Read More

Golang program to compare two strings lexicographically

Akhil Sharma
Updated on 20-Feb-2023 10:41:54

3K+ Views

In Golang, lexicographic comparison refers to comparing strings in a manner similar to how they would be compared in a dictionary where the words are listed alphabetically. This means that the initial character of each string is used to compare the individual characters of two strings in order. The comparison process continues until a difference is discovered or one of the strings' ends is reached if the initial few characters are the same. The string that appears first in the lexical order is regarded as being "less than" the other. Let’s see via examples how to execute this program. Method ... Read More

Golang program to print first letter of each word using regex

Akhil Sharma
Updated on 20-Feb-2023 10:41:04

590 Views

A string of characters known as a regular expression (regex or regexp) creates a search pattern. Regular expressions are frequently employed to carry out string matching, sometimes known as "find and replace, " or pattern matching with strings. Input validation, parsing, and other tasks are also possible with them. Regular expressions use special characters and metacharacters to specify the pattern to be matched, and their syntax differs widely between computer languages. Let’s see different Golang examples to get a clear view of the concept. Method 1: Using regex.MustCompile() function In this example, we will see how to print first ... Read More

Golang program to remove leading zeros

Akhil Sharma
Updated on 20-Feb-2023 10:19:52

3K+ Views

Removing any zeros that appear at the start of a number or string is referred to as "removing leading zeros" in Golang. Leading zeroes are frequently included for formatting or alignment needs, although they don't convey any significant information. They can be eliminated to improve the number's or string's usability and human-readableness. It's important to keep in mind that leading zeroes can occasionally be crucial for specific applications, such as some financial or scientific ones. Let’s see through this program to get a clear understanding of the concept. In this program we will learn how to remove leading zeros using ... Read More

Golang program to swapping pair of characters

Akhil Sharma
Updated on 20-Feb-2023 10:18:38

1K+ Views

A string in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. Let’s see how the logic can be executed. In this article, we will inculcate the ways to swap pair of characters in the string using different set of examples. Syntax func len(v Type) int The len() function is used ... Read More

Golang program to compute all the permutations of the string

Akhil Sharma
Updated on 20-Feb-2023 10:15:54

838 Views

In the Go programming language, strings are a built-in data type that represents sequences of characters. They are defined using double quotes (") and can contain any valid Unicode characters. A permutation of a string is a distinct string with the same characters but a different ordering of the characters. For instance, the words "abcd" and "dabc" are combinations of one another. Here, in this program we will explore method to find permutation of string and print the output on the console using print statement in Golang. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used ... Read More

Golang Program to Differentiate String == operator and equals() method

Akhil Sharma
Updated on 20-Feb-2023 10:14:39

1K+ Views

In the Go programming language, strings are a built-in data type that represents sequences of characters. They are defined using double quotes (") and can contain any valid Unicode characters. The == operator in Go is used to determine whether two values, including strings, are equal. The == operator determines whether two operands are equal by comparing their values and returning a boolean value. On the other hand, the strings package's EqualFold() method examines two strings case-insensitively and returns a boolean value indicating whether or not they are equal. Method 1: Using bytes.Equal() method In this example we will ... Read More

Golang program to create a multi-line string using '%Q

Akhil Sharma
Updated on 20-Feb-2023 10:13:43

719 Views

In the Go programming language, strings are a built-in data type that represents sequences of characters. They are defined using double quotes (") and can contain any valid Unicode characters. The multi-line will be printed using backticks and the output will be printed on the console using fmt package. Let’s see different examples to get a clear understanding of the concept. The fmt employs the verb %q. To print the string in a format that can be securely included inside double-quoted string literals, use the printf function. This guarantees that any special characters, such as newlines, in the string will ... Read More

Advertisements