strings.ToValidUTF8() Function in Golang With Examples Last Updated : 17 May, 2020 Comments Improve Suggest changes Like Article Like Report strings.ToValidUTF8() Function in Golang is used to returns a copy of the string s with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty. Syntax: func ToValidUTF8(str, rep string) string Here, str is string which may contain invalid UTF-8 and rep is the replacement string. Return Value: It returns the replaced string. Example 1: C // Golang program to show the usage // of strings.ToValidUTF8() Function package main // importing fmt and strings import ( "fmt" "strings" ) // calling main method func main() { // There is no invalid UTF-8 character // present, so the same string returned fmt.Print(strings.ToValidUTF8("This is GeeksForGeeks", " ")) } Output: This is GeeksForGeeks Example 2: C // Golang program to show the usage // of strings.ToValidUTF8() Function package main // importing fmt and strings import ( "fmt" "strings" ) // calling main method func main() { // Invalid UTF-8 '\xc5' replaced by 'For' fmt.Print(strings.ToValidUTF8("Geeks\xc5Geeks", "For")) } Output: GeeksForGeeks Comment More infoAdvertise with us Next Article strings.ToValidUTF8() Function in Golang With Examples P PranchalKatiyar Follow Improve Article Tags : Go Language Golang-String Similar Reads 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 strings.TrimFunc() Function in Golang With Examples strings.TrimFunc() Function in Golang is used to returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed. Syntax: func TrimFunc(s string, f func(rune) bool) string Here, s is the string and function checks the value of rune and returns true if it c 2 min read strings.TrimLeftFunc() Function in Golang With Examples strings.TrimLeftFunc() Function returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed. Syntax: func TrimLeftFunc(s string, f func(rune) bool) string Here, s is the string and func() is the method which satisfies the string characters. Return Value: It returns 2 min read strings.TrimRightFunc() Function in Golang With Examples strings.TrimRightFunc() Function returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed. Syntax: func TrimRightFunc(s string, f func(rune) bool) string Here, s is the string and func() is the method which satisfies the string characters. Return Value: It retu 2 min read strings.ToUpperSpecial() Function in Golang With Examples strings.ToUpperSpecial() Function in Golang is used to returns a copy of the string s with all Unicode letters mapped to their upper case using the case mapping specified by c. Syntax: func ToUpperSpecial(c unicode.SpecialCase, s string) string Here, c is the case mapping and s is the specified stri 1 min read Like