Syed Abeed

Syed Abeed

26 Articles Published

Articles by Syed Abeed

26 articles

How to use ContainsAny() function in Golang?

Syed Abeed
Syed Abeed
Updated on 14-Mar-2022 973 Views

Golang has a built-in string function called ContainsAny() that we can use to check whether a specified string is present in a given string or not.ContainsAny() is completely different from Contains().Contains() is used to detect if a string contains a substring.ContainsAny() is used to detect if a string contains any characters in the provided string. Even if one character of the specified string is present in the original given string, then it returns True, else False.Syntaxfunc ContainsAny(s, chars string) boolWhere, s – Original Stringchars string – Substring where we define the string or characters.It returns a Boolean value.ExampleContainsAny() is case-sensitive, ...

Read More

How to convert a string into Title Case in Golang?

Syed Abeed
Syed Abeed
Updated on 10-Mar-2022 5K+ Views

Title() is a built-in function of strings package in Golang that is used to convert a string into Title Case. It converts the first character of each word in a given string into uppercase and returns the modified string.Syntaxfunc Title(s string) stringWhere s is the given string.Example 1Let us consider the following example −package main import (    "fmt"    "strings" ) func main() {    // Intializing the Strings    m := "title string function"    n := "Golang string package fUNCTION"    // Display the Strings    fmt.Println("String 1:", m)    fmt.Println("String 2:", n)    // ...

Read More

strings.SplitAfter() Function in Golang

Syed Abeed
Syed Abeed
Updated on 10-Mar-2022 2K+ Views

strings.SplitAfter() is a built-in function in Golang that is used to break a string into a slice. SplitAfter is different from other Split functions. Here, we slice a given string into substrings after each instance of separators and it returns a slice of those substrings.Syntaxfunc SplitAfter(S String, sep string) []stringWhere s is the given string and sep is the separator string.Example 1Consider the following example −package main import (    "fmt"    "strings" ) func main() {    // Intializing the Strings    x := "Golang Program of SplitAfter Function"    y := "1.2.3.4.5.6.7.8"        // Display the ...

Read More

Golang – strings.SplitN()

Syed Abeed
Syed Abeed
Updated on 10-Mar-2022 1K+ Views

strings.SplitN() is a built-in function in Golang that is used to split a given string into substrings by the given separator. It returns the slices of the substrings between those separators.Syntaxfunc SplitN(str, sep string, n int) []stringWhere, str is the given input string, sep is the separator string, andn defines the number of substrings that is to be returned.Example 1Consider the following example −package main import (    "fmt"    "strings" ) func main() {    // Intializing the Strings    p := "1, 2, 3, 4, 5, 6, 7"    q := "Welcome to Golang Programming Language"    r := ...

Read More

How to repeat a string for a specified number of times in Golang?

Syed Abeed
Syed Abeed
Updated on 10-Mar-2022 3K+ 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

How to find the last index value of a string in Golang?

Syed Abeed
Syed Abeed
Updated on 10-Mar-2022 4K+ 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

strings.IndexByte() Function in Golang

Syed Abeed
Syed Abeed
Updated on 10-Mar-2022 371 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

strings.IndexAny() Function in Golang

Syed Abeed
Syed Abeed
Updated on 10-Mar-2022 440 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

How to find the Index of a string in Golang?

Syed Abeed
Syed Abeed
Updated on 10-Mar-2022 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 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

Replace() vs ReplaceAll() in Golang

Syed Abeed
Syed Abeed
Updated on 10-Mar-2022 20K+ 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
Showing 1–10 of 26 articles
« Prev 1 2 3 Next »
Advertisements