


The first part of this tool reads two flags - path to text files and resulting csv name.įlags are first-level citizen in go, and it’s quite easy to use them for basic variables (booleans, integers, and strings).įor scanner. Below are some simple comments to get you through it. The code with tests is available on GitHub. Comming from Java, it feels so good not needing to use third party depedencies, even for simplest things. Download Doxillion Document Converter Software 2.
#TEXT TO CSV CONVERTER HOW TO#
Therefore, I trimmed the extra spaces using regex.Įverything is done using the standard library only - which is a great asset in Go. How to Convert CSV to TXT with Doxillion Document Converter Software 1. 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.
