Created
October 11, 2017 14:52
-
-
Save AlexeySoshin/770a144b4349b6fcc7885335d17dfb8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"unicode/utf8" | |
) | |
func main() { | |
word := `Maximilianstraße` | |
wordLen := len(word) | |
fmt.Println(wordLen) //17 | |
fmt.Println(word[wordLen-2 : wordLen-1]) //� | |
fmt.Println(word[14:15]) //� | |
fmt.Println(word[15:16]) //� | |
fmt.Println(word[14:16]) //ß | |
wordLen = utf8.RuneCountInString(word) | |
fmt.Println(wordLen) //16 | |
utf8Runes := []rune(word) | |
sharpS := string(utf8Runes[14:15]) | |
fmt.Println(sharpS) //ß | |
i := 0 | |
for _, _ = range word { | |
i++ | |
} | |
fmt.Println(i) //16 | |
for i, c := range word { | |
fmt.Printf("%d:%c ", i, c) | |
} | |
// 0:M 1:a 2:x 3:i 4:m 5:i 6:l 7:i 8:a 9:n 10:s 11:t 12:r 13:a 14:ß 16:e | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment