How to split string with Golang !

Splitting strings in golang

Split command in the strings package can help us !
str := "Test message !"
splittedStr := strings.Split(str, " ")
fmt.Println(len(splittedStr))
fmt.Println(splittedStr[0])

result :

3 Test

Also we can use strings.Fields command for parsing by space

fields := strings.Fields("Test Value!")
fmt.Println(len(fields))
fmt.Println(fields[0])

result :

2 Test

Rate Post :
Similar Posts :
Comments :