- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1082 Articles for Go Programming

6K+ Views
strings.Split() is used to break a string into a list of substrings using a specified delimiter. It returns the substrings in the form of a slice.SyntaxThe syntax of strings.Split() is as follows −func Split(S string, sep string) []stringWhere s is the given string and sep is the delimiter (separator) string. It returns the substrings.Example 1Let us consider the following example −package main import ( "fmt" "strings" "regexp" ) func main() { // Intializing the Strings p := "oopsfunctions" q := "GoLang language" // Display the Strings fmt.Println("String 1:", p) fmt.Println("String ... Read More

2K+ Views
strings.Repeat() is a built-in function in Golang that is used to repeat a string for a specified number of times. It returns a new string which consists of a new count of copies of the given string.SyntaxIts syntax is as follows −func Repeat(s string, count int) stringWhere s is the given string and count represents how many times you want to repeat the string. It returns a new string.Example 1The following example demonstrates how you can use the Repeat() function −package main import ( "fmt" "strings" ) func main() { // Initializing the Strings x := ... Read More

3K+ Views
LastIndex() is a built-in function of strings package in Golang. This function is used to check the index of the last occurrence of a specified substring in a given original string. If the substring is found in the given string, then it returns its index position, starting from 0; otherwise it returns "-1".SyntaxThe syntax of LastIndex() is −func LastIndex(str, substr string) intWhere, str is the string inside which we need to search, andsubstr is the substring that we want to search inside the str.Example 1Let us consider the following example −package main import ( "fmt" "strings" ) func ... Read More

973 Views
The simplest way to concatenate two strings in Golang is to use the "+" operator. For example, Example 1package main import ( "fmt" ) func main() { str1 := "Hello..." str2 := "How are you doing?" fmt.Println("1st String:", str1) fmt.Println("2nd String:", str2) // Concatenate using the + Operator fmt.Println("Concatenated String:", str1 + str2) }OutputIt will produce the following output1st String: Hello... 2nd String: How are you doing? Concatenated String: Hello...How are you doing?Concatenate using strings.Join()strings.Join() is a built-in function in Golang which is used to concatenate a slice ... Read More

136 Views
IndexByte() is an inbuilt function of strings package in Golang. This function returns the index of the first occurrence of a character in a given string. If the character is found, then it returns its index, starting from 0; else it returns "-1".Syntaxfunc IndexByte(str string, chr byte) intWhere, str – It is the original string.chr – Character (byte) to be checked in the string.Example 1Let us consider the following example −package main import ( "fmt" "strings" ) func main() { // Initializing the Strings m := "IndexByte String Function" n := "Golang IndexByte String Package" ... Read More

177 Views
strings.IndexAny is a built-in function in Golang which is used to get the index of the first instance of any Unicode code point from the input substring. If the substring is found, it returns the position starting from 0; else it returns -1.Syntaxfunc IndexAny(s, chars string) intWhere, s – The original given string.chars – It is the substring that is to be checked in the given string.Example 1Take a look at the following example.package main import ( "fmt" "strings" ) func main() { // Defining the Variables var str string var charstring string var ... Read More

10K+ 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 given stringsubstring – It is the string whose Index value we need to findExample 1Let us consider the following example −package main import ( "fmt" "strings" ) // Main function func main() { // Initializing the Strings x := "Learn Golang on Tutorialspoint" ... Read More

11K+ 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 −func ReplaceAll(s, old, new string) stringWhere, s is the given stringold is the string which we want to replace, andnew is string which will replace the old string.Example 1Let us consider the following example −package main import ( "fmt" "strings" ) func main() { // Initializing ... Read More

2K+ 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 particular set of characters, respectively.Syntaxfunc HasSuffix(s, prefix string) boolWhere x is the given string. It returns a Boolean value.Example 1In this example, we are going to use HasSuffix() with an if condition to check wheter two defined string variables are ending with the same set of characters or not.package main import ... Read More

3K+ 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. It returns a Boolean value.ExampleIn this example, we are going to use HasPrefix() along with an if condition to check wheter the two defined variables are starting with the same Prefix string or not.package main import ( "fmt" "strings" ) func main() { // Initializing ... Read More