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.

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)
}
}
Output:
This
is
a
sample
sentence.

More Go language topics,

Comments

Popular posts from this blog

Spring Boot OpenAI Integration: Step-by-Step Guide

Orchestration-Based Saga Architecture and Spring Boot Microservices Implementation Guide

Spring Boot 3 + Angular 15 + Material - Full Stack CRUD Application Example