How to iterate over words of String in Go Language?
Hello everyone, in this tutorial we will show you how to iterate over all the words of String in the Go Programming language.
Output:
How to iterate over all the words of the string in Go Language?
Using for-range loop
package main
import (
"fmt"
"strings"
)
func main() {
teststr := "This is a sample sentence."
str := strings.Fields(teststr)
for _, word := range str {
fmt.Println(word)
}
}
This
is
a
sample
sentence.
More Go language topics,