How to access individual runes using for range loop in GoLang 1.20
In this video we are going to generate source code for the GoLang Program, How to access individual runes using for range loop using chatGPT.
After generating we will verify and run the generated code.
Important note on source code: only source code that are acceptable by the youtube description box will be displayed.
##############SOURCE CODE#########################
package main
import "fmt"
func main() {
str := "Hello, 世界"
for _, r := range str {
fmt.Printf("Rune: %c\n", r)
}
}
Below is the explanation for the program:
In this program, we define a string str with the value "Hello, 世界". The string contains both ASCII and non-ASCII characters.
We then use a for range loop to iterate over each rune of the string.
The for range loop returns two values on each iteration: the index of the current rune (which we don't need, so we use the blank identifier _),
and the rune itself, which we assign to the variable r.
Inside the loop, we use the %c format specifier to print out the current rune.
#go #goprogramming #golang #golangtutorial #golanguage