Skip to content

Instantly share code, notes, and snippets.

@tyochiai
Last active December 28, 2015 07:09
Show Gist options
  • Save tyochiai/7462167 to your computer and use it in GitHub Desktop.
Save tyochiai/7462167 to your computer and use it in GitHub Desktop.
文字列の先頭に半角スペースを持つ Shift_JIS で encoding/csv が文字化ける
package main
import (
"code.google.com/p/mahonia"
"encoding/csv"
"os"
)
func main() {
sjis := mahonia.NewEncoder("Shift_JIS")
with_space := sjis.ConvertString(" ほげ")
record := []string{with_space}
file, _ := os.Create("output.csv")
defer file.Close()
writer := csv.NewWriter(file)
writer.Write(record)
writer.Flush()
}
// output
// 22 20 EF BF BD D9 82 EF BF BD 22 0A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment