Skip to content

Instantly share code, notes, and snippets.

@doccaico
Last active February 3, 2025 23:52
Show Gist options
  • Save doccaico/180486dbbdbbff52b66f30b1947513ce to your computer and use it in GitHub Desktop.
Save doccaico/180486dbbdbbff52b66f30b1947513ce to your computer and use it in GitHub Desktop.
Dlangで日本語出力 (cmd.exe and powershell.exe)
import std.stdio : writeln;
import std.conv : to;
import std.windows.charset : toMBSz;
import core.sys.windows.windows : GetConsoleOutputCP;
void main()
{
auto currentCodePage = GetConsoleOutputCP();
writeln(currentCodePage);
string utf8_string = "あいうえお"; // UTF8
writeln("utf8 to sjis: ", to!string(toMBSz(utf8_string)));
writeln("utf8 to sjis: ", to!string(toMBSz(utf8_string, 932)));
// $ rdmd jp.d
//
// 932
// utf8 to sjis: あいうえお
// utf8 to sjis: あいうえお
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment