Removing Leading and Trailing White Spaces from Strings in Go:
To effectively trim the leading and trailing white spaces of a string variable in Go, there is a built-in function called strings.TrimSpace(s). This function removes all leading and trailing whitespace from the input string s.
Example:
package main import ( "fmt" "strings" ) func main() { s := "\t Hello, World\n " fmt.Printf("%d %q\n", len(s), s) t := strings.TrimSpace(s) fmt.Printf("%d %q\n", len(t), t) }
Output:
16 "\t Hello, World\n " 12 "Hello, World"
The above is the detailed content of How to Remove Leading and Trailing Whitespace from Strings in Go?. For more information, please follow other related articles on the PHP Chinese website!