1.字节(byte)
package main
import (
"bytes"
"fmt"
)
func main ( ) {
var aa [ ] byte = [ ] byte { 'a' , 'b' , 's' }
fmt. Printf ( "%T %#v\n" , aa, aa)
s := string ( aa)
fmt. Printf ( "%T %#v\n" , s, s)
bs := [ ] byte ( s)
fmt. Printf ( "%T %#v\n" , bs, bs)
fmt. Println ( bytes. Compare ( [ ] byte ( "abc" ) , [ ] byte ( "def" ) ) )
fmt. Println ( bytes. Index ( [ ] byte ( "abcdefabc" ) , [ ] byte ( "abc" ) ) )
fmt. Println ( bytes. Contains ( [ ] byte ( "abcdefabc" ) , [ ] byte ( "oo" ) ) )
bytes02 := [ ] byte { 'a' , 'b' , 'c' }
bytes03 := [ ] byte { 'c' , 'b' }
fmt. Println ( bytes. Contains ( bytes02, bytes03) )
fmt. Println ( bytes. Compare ( bytes02, bytes03) )
}
2.unicode/utf8
package main
import (
"fmt"
"unicode/utf8"
)
func main ( ) {
s := "我爱中华人名共和国"
fmt. Println ( len ( s) )
fmt. Println ( utf8. RuneCountInString ( s) )
}