文字コード変換

Contents

出力結果

%BC%D6
車

プログラムコード

JavaScript

const iconv = require('iconv-lite')
const fs = require("fs");
let utf8str = "車"
let eucbuffer = iconv.encode(utf8str, 'eucjp')
console.log( [...eucbuffer ].map(n => `%${n.toString(16).toUpperCase()}`).join("") )
utf8str = iconv.decode(eucbuffer, 'eucjp')
console.log(utf8str)

PHP

<?php
$utf8str = "車";
$eucstr = mb_convert_encoding( $utf8str, 'euc-jp', 'utf8');
print rawurlencode($eucstr)."\n";
$utf8str = $eucstr;
$utf8str = mb_convert_encoding( $utf8str, 'utf8', 'euc-jp');
print $utf8str."\n";

Perl

use Encode::EUCJPMS;
use URI::Escape;
my $utf8str = "車";
my $eucstr = $utf8str;
Encode::from_to($eucstr, "utf8", "eucjp-ms");
print uri_escape($eucstr)."\n";
$utf8str = $eucstr;
Encode::from_to($utf8str, "eucjp-ms", "utf8");
print($utf8str."\n");

Python

import urllib.parse
utf8str = "車"
eucstr = utf8str.encode('euc-jp')
print(urllib.parse.quote(eucstr))
print(eucstr.decode('euc-jp'))

Ruby

require 'uri'
utfstr = "車"
eucstr = utfstr.encode("EUC-JP")
print(URI.escape(eucstr)+"\n")
utfstr = eucstr.encode("UTF-8", "EUC-JP")
print(utfstr+"\n")