Finally finished the 'separar_letras' exercise

This commit is contained in:
raul 2024-01-16 19:06:32 +01:00
parent 1e2bef7cd9
commit 696c069209
1 changed files with 15 additions and 1 deletions

View File

@ -7,5 +7,19 @@ func main() {
fmt.Scan(&palabra)
// TODO: fix this garbage
fmt.Printf("Your word is %v\n", palabra)
//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]))
}
}