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

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

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

Java - Blowfish Encryption and decryption Example

Java - DES Encryption and Decryption example

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

ReactJS - Bootstrap - Buttons

Spring Boot 3 + Spring Security 6 + Thymeleaf - Registration and Login Example

File Upload, Download, And Delete - Azure Blob Storage + Spring Boot Example

Top 5 Java ORM tools - 2024

Java - How to Count the Number of Occurrences of Substring in a String