Check If a String is Empty in Go

Akhil Sharma
Updated on 13-Feb-2023 16:22:52

2K+ Views

In Go, a string is a sequence of characters. It is an immutable data type, meaning that once a string is created, it cannot be modified. Strings are enclosed in double quotes ("") and can contain any combination of letters, numbers, and symbols. They are commonly used to store text and are often used as input and output in programs. Syntax func len(v Type) int The len() function is used to get the length of a any parameter. It takes one parameter as the data type variable whose length we wish to find and returns the integer value ... Read More

Find All Subsets of a String in Go

Akhil Sharma
Updated on 13-Feb-2023 16:21:25

821 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. Algorithm Step 1 − Create a package main and declare fmt(format package) and sort package in the program where main produces executable codes and fmt helps in formatting input and output. Step 2 − Create a main function and ... Read More

Golang Program to Shuffle the Elements of an Array

Akhil Sharma
Updated on 13-Feb-2023 16:14:16

991 Views

An array is a fixed sequence of elements in which the elements are placed at contiguous memory locations. We will shuffle and randomly place the elements of the array. In the first case we will use fisher-yates shuffle algorithm. Let’s see how we can execute it using different logics in the Golang code. 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 function generates the current local time. to ... Read More

Compare Two Strings in Go

Akhil Sharma
Updated on 13-Feb-2023 16:12:08

853 Views

In go programming language, string is one of the data-types that can be used for various application. It is a collection of characters and is also immutable. In go programming language a string can't be modified after they have been created. In this article, we are going to study different techniques to compare two given strings. Syntax bytes.Equal(s1, s2) Two slices of bytes ([]byte) are compared using the Equal() method to see if they are equal. If the two slices of bytes are equal, it produces a boolean result (true or false) reflecting that fact. strings.Compare(s1, s2) The ... Read More

Remove a Subset from a Slice in Golang

Akhil Sharma
Updated on 13-Feb-2023 16:11:33

530 Views

Slice is similar to an array, the only difference is that an array is a fixed sequence of elements whereas slice the array elements are dynamic. This makes the slice more efficient and faster in various applications. In slice, the elements are passed by reference instead of values. In this article, we will learn different techniques to remove a subset from slice using go language programming Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array to which we ... Read More

Go Program to Sort a String

Akhil Sharma
Updated on 13-Feb-2023 16:10:08

6K+ 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. In this article, we will learn different techniques to sort a string using different set of examples. Syntax func Split(str, sep string) []string Split() function is used to split a string through a provided separator. This function is present ... Read More

Rotate Elements of a Slice in Go

Akhil Sharma
Updated on 13-Feb-2023 16:09:32

662 Views

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, which means 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. Here will learn various techniques to rotate elements of a slice using go programming language. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array ... Read More

Check If a Set Is the Subset of Another Slice in Golang

Akhil Sharma
Updated on 13-Feb-2023 16:08:32

2K+ Views

Slice is similar to the array, the only difference is that an array is a fixed sequence of elements whereas slice the array elements are dynamic. This makes slice more efficient and faster in various applications. In slice the elements are passed by reference instead of values. In this article, we are going to learn various techniques to check if a set of one slice is a subset of another slice or not using Go programming language. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and ... Read More

Convert Slice into Array in Go

Akhil Sharma
Updated on 13-Feb-2023 16:07:08

5K+ Views

A slice can also be called as a dynamic array as its value is dynamic whereas a normal array is static. This makes the slice more efficient and faster. They are passed by reference instead of value. Here we are going to learn different techniques of converting a slice into array using various examples. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array to which we wish to add the values followed by the values to add. The ... Read More

Golang Program to Make String Immutable

Akhil Sharma
Updated on 13-Feb-2023 16:06:07

290 Views

Strings are by default immutable in Go. A string cannot be changed once it has been created. A compile-time error will appear if the value of a string is attempted to be changed. Therefore, there is no need to add any more logic to make it immutable. Let’s see how the execution is done. Here we are going to learn different techniquest of making a string immutable using go programming. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and output. ... Read More

Advertisements