Hello all.
I need work with information, which written in UTF-16 file.
I’m new in Go, but heard that he is good Unicode support.
So my task is to extract the text in string for further work.
I tried to do the conversion in the forehead, but it turned out badly:
package main
import (
"bufio"
"fmt"
"log"
"os"
utf16 "unicode/utf16"
)
func main() {
file, err := os.Open("in.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
fscanner := bufio.NewScanner(file)
for fscanner.Scan() {
arrbytes := fscanner.Bytes()
slice := make([]uint16, len(arrbytes))
for i := range arrbytes {
slice[i] = uint16(arrbytes[i])
}
newarr := utf16.Decode(slice)
fmt.Println(string(newarr))
}
}
I would appreciate any help on this issue.