Golang unicode.SimpleFold() function example

package unicode

SimpleFold returns the equivalent unicode in Upper case if input is lower case and vice-versa.

 package main

 import (
 "fmt"
 "unicode"
 )

 func main() {
 sr := unicode.SimpleFold('\u212A')
 fmt.Println(sr) // wrong way to print!

 fmt.Printf("%+q\n", sr) // simpleFold will return K (Kelvin symbol)

 src := unicode.SimpleFold('你')
 fmt.Printf("%q\n", src)  // simpleFold will return the same character 你
 fmt.Printf("%+q\n", src) // simpleFold will return the unicode codepoint

 sra := unicode.SimpleFold('A')
 fmt.Printf("%+q\n", sra) // simpleFold will return the lower case 'a'

 }

Output :

75

'K'

'你'

'\u4f60'

'a'

References :

http://golang.org/pkg/unicode/#SimpleFold

https://blog.golang.org/strings

Advertisement