Skip to content

Instantly share code, notes, and snippets.

@jinwoo1225
Created October 26, 2021 06:04
Show Gist options
  • Save jinwoo1225/6629f6f0c828d8523024e42b4b713b86 to your computer and use it in GitHub Desktop.
Save jinwoo1225/6629f6f0c828d8523024e42b4b713b86 to your computer and use it in GitHub Desktop.
go lang length of string
package main
import (
"fmt"
"strings"
)
func main() {
//https://golang.org/doc/effective_go#for
korean := "한국어" // korean 3words
english := "eng" // english 3words
outOfASCII := "àšź" // idk 3words
fmt.Printf("%T\n", korean) // string은 비정형?....
fmt.Printf("%T\n", english)
fmt.Printf("%T\n", outOfASCII)
fmt.Println(strings.Repeat("-", 10))
fmt.Println(len(korean))
fmt.Println(len(english))
fmt.Println(len(outOfASCII))
fmt.Println(strings.Repeat("-", 10))
fmt.Println(len([]rune(korean)))
fmt.Println(len([]rune(english)))
fmt.Println(len([]rune(outOfASCII)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment