Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.
This project is maintained by Kray-G
The Iconv
class is used to convert the encoding of text.
The constructor will get to
and from
codepage like this.
var converter = new Iconv({ to: "UTF8", from: "CP932" });
“CP932” is the code page of Shift JIS.
For example, the following example shows converting from “CP932” to “UTF8”.
var converter = new Iconv({ to: "UTF8", from: "CP932" });
// Unary asterisk will convert a binary to a string.
var sjis = *<0x82, 0x60, 0x82, 0x61, 0x82, 0x62, 0x82, 0x63, 0x82, 0x64, 0x82, 0x65>;
var val = converter.convert(sjis);
System.println(val); // => ABCDEF
You can also input a binary and output a binary.
binmode()
means an output is a binary style.
var converter = new Iconv({ to: "UTF8", from: "CP932" });
var sjis = <0x82, 0x60, 0x82, 0x61, 0x82, 0x62, 0x82, 0x63, 0x82, 0x64, 0x82, 0x65>;
converter.binmode();
var val = converter.convert(sjis);
System.println(val); // => <0xef, 0xbc, 0xa1, 0xef, 0xbc, 0xa2, 0xef, 0xbc, 0xa3, 0xef, 0xbc, 0xa4, 0xef, 0xbc, 0xa5, 0xef, 0xbc, 0xa6>
System.println(*val); // => ABCDEF
var converter = new Iconv({ to: "UTF8", from: "CP932" });
var sjis = *<0x82, 0x60, 0x82, 0x61, 0x82, 0x62, 0x82, 0x63, 0x82, 0x64, 0x82, 0x65>;
var val = converter.convert(sjis); // val is a string.
System.println(<...val>);
<0xef, 0xbc, 0xa1, 0xef, 0xbc, 0xa2, 0xef, 0xbc, 0xa3, 0xef, 0xbc, 0xa4, 0xef, 0xbc, 0xa5, 0xef, 0xbc, 0xa6>
var converter = new Iconv({ to: "UTF8", from: "CP932" });
// Unary asterisk will convert a binary to a string.
var sjis = *<0x82, 0x60, 0x82, 0x61, 0x82, 0x62, 0x82, 0x63, 0x82, 0x64, 0x82, 0x65>;
converter.binmode();
var val = converter.convert(sjis);
System.println(val);
<0xef, 0xbc, 0xa1, 0xef, 0xbc, 0xa2, 0xef, 0xbc, 0xa3, 0xef, 0xbc, 0xa4, 0xef, 0xbc, 0xa5, 0xef, 0xbc, 0xa6>
var converter = new Iconv({ to: "UTF8", from: "CP932" });
var sjis = <0x82, 0x60, 0x82, 0x61, 0x82, 0x62, 0x82, 0x63, 0x82, 0x64, 0x82, 0x65>;
var val = converter.convert(sjis); // val is a string.
System.println(<...val>);
<0xef, 0xbc, 0xa1, 0xef, 0xbc, 0xa2, 0xef, 0xbc, 0xa3, 0xef, 0xbc, 0xa4, 0xef, 0xbc, 0xa5, 0xef, 0xbc, 0xa6>
var converter = new Iconv({ to: "UTF8", from: "CP932" });
// Unary asterisk will convert a binary to a string.
var sjis = <0x82, 0x60, 0x82, 0x61, 0x82, 0x62, 0x82, 0x63, 0x82, 0x64, 0x82, 0x65>;
converter.binmode();
var val = converter.convert(sjis);
System.println(val);
<0xef, 0xbc, 0xa1, 0xef, 0xbc, 0xa2, 0xef, 0xbc, 0xa3, 0xef, 0xbc, 0xa4, 0xef, 0xbc, 0xa5, 0xef, 0xbc, 0xa6>