


Golang works with UTF-8 by default, so stdlib’s strings package didn’t behave well with provided text files (trimming, splitting).

The files provided to me by the client (the ones found in /testdata) were encoded in UTF-16. While solving this problem for my client, I couldn’t find a good tutorial on how to achieve this with Go (only few code snippets), so here’s one. The good thing is that the provided files were very simple, so they are perfect for a tutorial like this.Ĭonverting txt files to another format, especially a simple one like csv, is a standard beginner programming problem. Looking at the source files, I’m assuming the text files are generated by a script or a tool that extracts the data from somewhere. Recently I found a client that needed to convert a list of txt files into csv - and he wanted the solution to be written in Go.
