golang-exercises/separar_letras/main.go

26 lines
779 B
Go

package main
import "fmt"
func main() {
var palabra string
fmt.Scan(&palabra)
// TODO: fix this garbage
//fmt.Printf("Your word is %v\n", palabra)
//var count = len(palabra)
//fmt.Printf("Length is %v\n", count)
// So I'm converting the string to an array of "runes", which are apparently the equivalent of characters
var letras = []rune(palabra)
// Here I'm just using len function to properly count it because if you try to len a plain string it's just gonna
// return the bytes, not the actual amount of characters, so UTF-8 is not gonna be happy
fmt.Printf("%d letters\n", len(letras))
// I really have to start learning when to use printf and when to use println, println is useful
for i := 0; i < len(letras); i++ {
fmt.Println(string(letras[i]))
}
}