Found 1082 Articles for Go Programming

Golang program to find the frequency of character in a string

Akhil Sharma
Updated on 01-Feb-2023 19:13:57

638 Views

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. The frequency of a character means the number of times a character is appearing. Syntax map() To keep track of how frequently each character appears in the input string, the built-in map data structure in Go is used in example below. The map is an unsorted collection of key-value pairs with unique keys and variable types of values for the values. func ... Read More

Golang program to iterate through each character of string

Akhil Sharma
Updated on 01-Feb-2023 19:12:49

7K+ 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. Syntax func len(v Type) int The len() function is used to get the length of any parameter. It takes one parameter as the data type variable whose length we wish to find and returns the integer value which is ... Read More

Golang program to capitalize first character of each word in a string

Akhil Sharma
Updated on 01-Feb-2023 19:11:55

5K+ 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. Syntax strings.Join(words, ” ”) A slice of strings can be joined together with a separator using the join method. Two arguments are required by the function: a slice of strings, and a separator string. It gives back a single ... Read More

Golang program to create random strings

Akhil Sharma
Updated on 19-Jul-2023 14:31:01

92 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. Syntax rand.Seed(value) Rand.Seed() function is used to generate random numbers. It takes a user input as argument which is the upper limit for generating random numbers. func Now() Time The Now() function is defined in time package. this ... Read More

Golang program to clear the string buffer

Akhil Sharma
Updated on 01-Feb-2023 19:07:48

968 Views

When a string buffer is cleared, all of the data that was previously stored inside the buffer is deleted. This can be done for a variety of reasons, including when you want to reuse the buffer for fresh data or when the data that is currently in the buffer is no longer required. Here we will understand different techniques of clear a string buffer using go programming language Syntax Reset() Any accumulated data is discarded and the buffer is reset to zero using the Reset() method. The old buffer is essentially replaced with a new one and the old ... Read More

Golang program to check if a string contains a substring

Akhil Sharma
Updated on 01-Feb-2023 19:06:02

504 Views

A substring is a small string in a string and 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. Syntax strings.Contains(str, substring string) To determine whether a string contains a particular substring, use the Contains(s, substr string) bool function. If the substring is found in the supplied string, a ... Read More

Golang program to show data hiding in class

Akhil Sharma
Updated on 01-Feb-2023 19:04:51

233 Views

In Golang, data hiding is a practice of preventing external code from accessing or changing a class’s members. This is accomplished by designating the class's members as private, which restricts access to or modification of them to the class's methods only. This is a crucial idea in object-oriented programming since it ensures the data's integrity and the class's proper operation. Syntax struct A struct is a composite data type used in the Go programming language that enables you to bring together related values of various types, such as a collection of fields or a collection of methods. Similar to ... Read More

Golang program to get maximum and minimum from a slice

Akhil Sharma
Updated on 23-Jan-2023 15:00:51

4K+ Views

In this article, we will see how to fetch maximum and minimum elements from a slice. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead by value. Let us understand this basic concept using different set of examples and algorithms based upon them. Method 1: Using the Helper Function In this method, we will learn how to get ... Read More

Golang to check if a slice is empty

Akhil Sharma
Updated on 23-Jan-2023 14:58:50

4K+ Views

In this article, we will check if the slice is empty or not using a variety of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s learn through examples how it can be executed. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. ... Read More

Golang program to check if two slices are equal

Akhil Sharma
Updated on 23-Jan-2023 14:55:05

1K+ Views

In this article, we will see what are the ways to check whether two slices are equal or not with the help of relevant examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead by value. Let us learn the concept through examples. Method 1: Using a built-in Function In this method, we will use reflect.DeepEqual() function from ... Read More

Advertisements