String.toZenkaku() ※出来てない
by ethertank
JavaScript
String.prototype.toZenkaku || (String.prototype.toZenkaku = function() {
var charCode,
i = 0,
len = this.length,
output = "";
for (; i < len; ++i) {
charCode = this.charCodeAt(i);
//濁点・半濁点が付いている可能性がある場合、
if (charCode >= 0x30AD && charCode <= 0x30DD) {
if(charCode[i+1].toString(16) == "ff9e"){
output += "゛";
++i;
} else if(charCode[i+1].toString(16) == "ff9f"){
output += "゜";
++i;
} else {
output += (charCode >= 0xFF66 && charCode <= 0xFF9F) ? String.fromCharCode(charCode - 0xcecf) : this[i];
}
} else {
output += (charCode >= 0xFF66 && charCode <= 0xFF9F) ? String.fromCharCode(charCode - 0xcecf) : this[i];
}
}
return output;
});
document.write('アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンガギグゲゴダヂヅデドパピプペポバビブベボァィゥェォッャュョ'.toZenkaku());
//ア = 12450
//alert(65393-12450);//52943
//alert(65393..toString(16));//ff71
//alert(52943..toString(16));//cecf
// "ア" = 0x00b1
// " " = 0x8340
/*
var han = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンガギグゲゴダヂヅデドパピプペポバビブベボァィゥェォッャュョ';
var hanc = [];
for(var i = 0; i < han.length; ++i){
hanc.push("0x" + han.charCodeAt(0).toString(16));
}
alert(hanc);
*/
//document.write(hanc);
//document.write(String.fromCharCode(0xFF66));//ヲ
//document.write(String.fromCharCode(0xFF99));//ル
//document.write(String.fromCharCode(0xFF9F));//゚
//alert("0x" + 65382..toString(16));//ff66
//alert("ヲ".charCodeAt(0).toString(16));//30f2
//alert(0xff66-0x30f2);//52852
//alert("0x" + 52852..toString(16));
//alert("ヲ".toZenkaku());
//alert("ヲ".charCodeAt(0).toString(16));//ff66
...