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,

Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

ReactJS, Spring Boot JWT Authentication Example

Top 5 Java ORM tools - 2024

Java - Blowfish Encryption and decryption Example

Spring boot video streaming example-HTML5

Google Cloud Storage + Spring Boot - File Upload, Download, and Delete