February 2018
Intermediate to advanced
340 pages
9h 43m
English
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(trimResult) stringWithSpaces := "\t\t\n Go \tis\n Awesome \t\t" r := regexp.MustCompile("\\s+") replace := r.ReplaceAllString(stringWithSpaces, " ") fmt.Println(replace) needSpace := "need space" fmt.Println(pad(needSpace, 14, "CENTER")) fmt.Println(pad(needSpace, 14, "LEFT")) } func pad(input string, padLen int, align string) string { inputLen := len(input) if inputLen >= padLen { return input ...Read now
Unlock full access