Skip to content

Instantly share code, notes, and snippets.

@itiut
Last active November 8, 2017 16:23
Show Gist options
  • Save itiut/674d7ff87ede8207549c4c2e85975d72 to your computer and use it in GitHub Desktop.
Save itiut/674d7ff87ede8207549c4c2e85975d72 to your computer and use it in GitHub Desktop.
`encoding/csv` reads UTF-8 BOM.
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
)
func main() {
file, err := os.Open("utf8bom.csv")
if err != nil {
log.Fatal(err)
}
defer file.Close()
reader := csv.NewReader(file)
headers, err := reader.Read()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%X\n", "col1") // => 636F6C31
fmt.Printf("%X\n", headers[0]) // => EFBBBF636F6C31
}
col1 col2
1 2
3 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment