strings.Map() Function in Golang With Examples Last Updated : 22 Dec, 2021 Comments Improve Suggest changes Like Article Like Report strings.Map() Function in Golang is used to return a copy of the string given string with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement. So whenever the user wants to make changes in a certain string, he can make use of the strings.Map() function. It replaces the character of a string with a user-desired character. If we need to mask certain characters including digits and spaces, this function can be used. Syntax: func Map(mapping func(rune) rune, s string) string The mapping func(rune) rune parameter defines the character with which the original character needs to be replaced while the s parameter defines the original string inputted by the user. Example 1: C // Golang program to illustrate // the strings.Map() Function package main import ( "fmt"; "strings" ) func main() { modified := func(r rune) rune { if r == 'e' { return '@' } return r } input:= "Hello, Welcome to GeeksforGeeks" fmt.Println(input) // using the function result := strings.Map(modified, input) fmt.Println(result) } Output: Hello, Welcome to GeeksforGeeks H@llo, W@lcom@ to G@@ksforG@@ks Explanation: In the above example, we have used strings.Map() function to modify a string. We have defined a variable named "modified" that replaces character 'e' in the string with the symbol '@'. Another variable named "input" takes an input string that needs transformation. Example 2: The strings.Map() function can also be used to remove the spaces between the words of a string. C // Golang program to illustrate // the strings.Map() Function package main import ( "fmt"; "strings" ) func main() { transformed := func(r rune) rune { if r == ' ' { return 0 } return r } input:= "GeeksforGeeks is a computer science portal." fmt.Println(input) // using the function output := strings.Map(transformed, input) fmt.Println(output) } Output: GeeksforGeeks is a computer science portal. GeeksforGeeksisacomputerscienceportal. Explanation: In the above example, we have used strings.Map() function to remove the spaces in between a string. We have defined a variable named "transformed" that eliminates space ' ' in the string. This is done by returning 0 at the place of spaces. Another variable named "input" takes an input string whose in-between spaces need to be removed. Comment More infoAdvertise with us Next Article strings.Map() Function in Golang With Examples P preetikagupta8171 Follow Improve Article Tags : Go Language Golang-String Similar Reads strings.Join() Function in Golang With Examples strings.Join() Function in Golang concatenates all the elements present in the slice of string into a single string. This function is available in the string package. Syntax: func Join(s []string, sep string) string Here, s is the string from which we can concatenate elements and sep is the separato 1 min read strings.SplitN() Function in Golang with Examples strings.SplitN() Function() is a string manipulation function in Go language. It is used to split a given string into substrings separated by a separator. This function returns the slices of all substrings between those separators. Syntax: func SplitN(s, sep string, n int) []string Here, s is the st 3 min read strings.Index() Function in Golang With Examples strings.Index() Function in Golang is used to get the first instance of a specified substring. If the substring is not found, then this method will return -1. Syntax: func Index(str, sbstr string) int Here, str is the original string and sbstr is a string whose we want to find index value. Example 1 2 min read strings.Replace() Function in Golang With Examples strings.Replace() Function in Golang is used to return a copy of the given string with the first n non-overlapping instances of old replaced by new one. Syntax: func Replace(s, old, new string, n int) string Here, s is the original or given string, old is the string that you want to replace. new is 2 min read strings.IndexAny() Function in Golang With Examples strings.IndexAny() Function in Golang is used to returns the index of the first instance of any Unicode code point from chars in the original string. If the Unicode code point from chars is not available in the original string, then this method will return -1. Syntax: func IndexAny(str, charstr stri 2 min read strings.LastIndex() Function in Golang With Examples strings.LastIndex() function in the Golang returns the starting index of the occurrence of the last instance of a substring in a given string. If the substring is not found then it returns -1. Thus, this function returns an integer value. The index is counted taking zero as the starting index of the 2 min read time.String() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The String() function in Go language is used to find a string that represents the duration formats as "24h6m0.7s". Here, the foremost zero units are deleted. And the stated duration with less than one-secon 2 min read reflect.String() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.String() Function in Golang is used to get the string v's underlying value, as a string. To access this function, 2 min read strings.Fields() Function in Golang With Examples strings.Fields() Function in Golang is used to splits the given string around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of str or an empty slice if str contains only white space. Syntax: func Fields(str string) []s 2 min read strings.NewReplacer() Function in Golang With Examples strings.NewReplacer() Function in Golang returns a new Replacer from a list of previous, new string sets. Substitutions are performed within the order they show up within the target string, without overlapping matches. The old string comparisons are done in argument order. The old string comparisons 1 min read Like