Syed Abeed has Published 40 Articles

How to find the Index of a string in Golang?

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 09:14:30

12K+ Views

Strings.Index is a built-in function in Golang that returns the index of the first instance of a substring in a given string. If the substring is not available in the given string, then it returns -1.SyntaxThe syntax of Index() is as follows −func Index(s, substring string) intWhere, s – Original ... Read More

How to compare two strings in Golang?

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 08:53:01

4K+ Views

Golang has a built-in string function called Compare() that we can use to compare two strings. Here strings are compared using the lexicographical order.Syntaxfunc Compare(a, b string) intReturn TypesIf the strings (a == b), it returns 0.If the strings (a > b), then it returns 1If the strings (a < ... Read More

Replace() vs ReplaceAll() in Golang

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 07:41:41

19K+ Views

ReplaceAll() function in Golang replaces all the occurrences of a given substring with a new value. In contrast, Replace() function is used to replace only some characters in a string with a new value. It replaces only a specified "n" occurrences of the substring.SyntaxThe syntax of ReplaceAll() is as follows ... Read More

How to check if a string ends with a specified Suffix string in Golang?

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 07:37:41

3K+ Views

The HasSuffix() function of string class in Golang is used to check whether a given string ends with a specified Suffix string or not. It returns True if the given string ends with the specified Suffix string; otherwise it returns False.HasSuffix() and HasPrefix() check if a string ends or starts with a ... Read More

How to check if a string starts with a specified Prefix string in Golang?

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 07:26:23

4K+ Views

The HasPrefix() function of string class in Golang is used to check whether a given string begins with a specified Prefix string or not. It returns True if the given string begins with the specified prefix string; otherwise it returns False.Syntaxfunc HasPrefix(s, prefix string) boolWhere x is the given string. ... Read More

How to Replace characters in a Golang string?

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 07:14:14

5K+ Views

The strings package of Golang has a Replace() function which we can use to replace some characters in a string with a new value. It replaces only a specified "n" occurrences of the substring.In addition to Replace(), there is a ReplaceAll() function that replaces all the occurrences of a given substring ... Read More

How to use the Fields() function in Golang?

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 07:08:43

949 Views

The strings package of Golang provides a Fields() method, which can be used to split a string around one or more instances of consecutive whitespace characters.The Fields() function splits a given string into substrings by removing any space characters, including newlines. And it treats multiple consecutive spaces as a single space.Syntaxfunc ... Read More

What is the EqualFold function in Golang?

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 07:00:55

678 Views

The EqualFold() function in Golang is an inbuilt function of strings package which is used to check whether the given strings (UTF-8 strings) are equal. The comparison is not case-sensitive. It accepts two string parameters and returns True if both the strings are equal under Unicode case-folding (i.e., case-insensitive), False ... Read More

How to count the number of repeated characters in a Golang String?

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 06:57:24

5K+ Views

Count() is a built-in function is Golang that can be used to count the number of non-overlapping instances of a character/string in a string.Syntaxfunc Count(s, sep string) intWhere, s – Original Stringsep – Substring which we want to count.It returns an Integer value.ExampleThe following example demonstrates how you can use ... Read More

How to use Contains() function in Golang?

Syed Abeed

Syed Abeed

Updated on 10-Mar-2022 06:42:28

6K+ Views

Golang has a set of built-in string functions that we can utilize to perform different types of operations on string data. Contains() is such a function that can be used to search whether a particular text/string/character is present in a given string. If the text/string/character is present in the given ... Read More

Advertisements