Created
May 7, 2022 15:11
-
-
Save tio-iis/75f317a6257a8242ad4b75c0a7a15658 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" | |
func main() { | |
//一文字でサイズがたまたま1になっている文字 | |
//message1 := "AB" | |
//fmt.Println(len(message1)) | |
//一文字だけど、サイズは1じゃない文字 | |
message2 := "あ" | |
fmt.Println(len(message2)) | |
//rune型という型のスライスに変換すると、 | |
//上手く文字数を取得することができる。 | |
//スライスにすることでlen()が想定通りに動く。 | |
//message3 := []rune("あ") | |
//fmt.Println(len(message3)) | |
//fmt.Println(len([]rune("あいうえお"))) | |
//UTF-8形式のコードポイントを出力する | |
//message4 := "A" | |
//fmt.Printf("%x\n", message4[0]) | |
//UTF-8形式のコードポイントを出力する | |
//message5 := "あ" | |
//fmt.Println("---") | |
//for i := 0; i < len(message5); i++ { | |
// fmt.Printf("%x\n", message5[i]) | |
//} | |
//fmt.Println("---") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment