Last active
February 11, 2024 10:36
-
-
Save heiwa4126/c7a43913fde7c02c5385d0247b13bc6e to your computer and use it in GitHub Desktop.
GolangでUTF8をShiftJISに変換する基本。
This file contains hidden or 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 ( | |
"fmt" | |
"golang.org/x/text/encoding/japanese" | |
"golang.org/x/text/transform" | |
"log" | |
) | |
func main() { | |
s := "世界の皆さん、こんにちは!" | |
t := japanese.ShiftJIS.NewEncoder() | |
sjisStr, _, err := transform.String(t, s) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println([]byte(sjisStr)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Go Playground
ふつうは
とかだと思う。