testunicode.go 581 B

1234567891011121314151617181920212223242526
  1. package main
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. )
  7. func main() {
  8. sText := "李志刚"
  9. textQuoted := strconv.QuoteToASCII(sText)
  10. textUnquoted := textQuoted[1 : len(textQuoted)-1]
  11. fmt.Println(textUnquoted)
  12. sUnicodev := strings.Split(textUnquoted, "\\u")
  13. var context string
  14. for _, v := range sUnicodev {
  15. if len(v) < 1 {
  16. continue
  17. }
  18. temp, err := strconv.ParseInt(v, 16, 32)
  19. if err != nil {
  20. panic(err)
  21. }
  22. context += fmt.Sprintf("%c", temp)
  23. }
  24. fmt.Println(context)
  25. }