Last active
December 28, 2015 07:09
-
-
Save tyochiai/7462167 to your computer and use it in GitHub Desktop.
文字列の先頭に半角スペースを持つ Shift_JIS で encoding/csv が文字化ける
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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