package main
import (
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
"fmt"
)
func main() {
bs_UTF16LE, _, _ := transform.Bytes(unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewEncoder(), []byte("测试"))
bs_UTF16BE, _, _ := transform.Bytes(unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewEncoder(), []byte("测试"))
bs_UTF8LE, _, _ := transform.Bytes(unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewDecoder(), bs_UTF16LE)
bs_UTF8BE, _, _ := transform.Bytes(unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewDecoder(), bs_UTF16BE)
fmt.Printf("%v\n%v\n%v\n%v\n", bs_UTF16LE, bs_UTF16BE, bs_UTF8LE, bs_UTF8BE)
}
网友评论