FirstUtf8 获取字符串的第一个utf8字符,如果字符串为空,则返回” 如果字符串不是ascii编码,则返回第一个utf8字符,如果是ascii编码,则返回第一个字符
(s string)
| 8 | // FirstUtf8 获取字符串的第一个utf8字符,如果字符串为空,则返回” |
| 9 | // 如果字符串不是ascii编码,则返回第一个utf8字符,如果是ascii编码,则返回第一个字符 |
| 10 | func (x *xString) FirstUtf8(s string) string { |
| 11 | if len(s) == 0 { |
| 12 | return "" |
| 13 | } |
| 14 | if s[0] < 128 { |
| 15 | return s[0:1] |
| 16 | } else if len(s) >= 3 { |
| 17 | return s[0:3] |
| 18 | } else { |
| 19 | return s |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | func (x *xString) Utf8Split(s string, length int) string { |
| 24 | if len(s) == 0 { |
no outgoing calls