How to trim leading and trailing whitespace from a string in Golang?

In Golang, you can use the strings.TrimSpace() function to trim leading and trailing whitespace from a string.

Here's an example:

package main import ( "fmt" "strings" ) func main() { str := " Hello, World! " trimmedStr := strings.TrimSpace(str) fmt.Printf("Original string: %s\n", str) fmt.Printf("Trimmed string: %s\n", trimmedStr) }

This will output:

Original string: Hello, World! Trimmed string: Hello, World!

As you can see, the strings.TrimSpace() function removes the leading and trailing whitespace from the string.