The string input could contain too much whitespace, too little whitespace, or unsuitable whitespace chars. This recipe includes tips on how to manage these and format the string to your needs.
Managing whitespace in a string
How to do it...
- Open the console and create the folder chapter02/recipe11.
- Navigate to the directory.
- Create a file named whitespace.go with the following content:
package main
import (
"fmt"
"math"
"regexp"
"strconv"
"strings"
)
func main() {
stringToTrim := "\t\t\n Go \tis\t Awesome \t\t"
trimResult := strings.TrimSpace(stringToTrim)
fmt.Println...