From 696c069209dc8637fe5765483826542756df16fc Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 16 Jan 2024 19:06:32 +0100 Subject: [PATCH] Finally finished the 'separar_letras' exercise --- separar_letras/main.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/separar_letras/main.go b/separar_letras/main.go index 70ab57f..100ccf2 100644 --- a/separar_letras/main.go +++ b/separar_letras/main.go @@ -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])) + } }