i have some input of weird chars which generated by program to stdout , i want to write a go script which monitoring the stdout to replace those characters.
i did some research it seems golang only support utf8 , i am interesting on decoding those characters using UTF decode something like : https://cafewebmaster.com/online_tools/utf8_encode for example :
ü will be -> ü
is there a golang function /library which helps with this /any example appreciated
Use the text/transform package. You need to know the encoding though...
Example reading an ISO8859 format textfile:
import (
"golang.org/x/text/transform"
"golang.org/x/text/encoding/charmap"
)
file,_ := os.Open("somefile.txt")
defer file.Close()
reader := transform.NewReader(file, charmap.ISO8859_15.NewDecoder())
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
line:=scanner.Text()
// process line
}