Last active
January 19, 2018 06:57
-
-
Save sanmai/852f954ec5aa9bd787a371aaad9ea598 to your computer and use it in GitHub Desktop.
Convert full-width digits to half-width (ASCII) digits. 入力値を半角に変換して返却する
This file contains 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
function toHankaku(original) { | |
var result = ''; | |
for (var i = 0; i < original.length; i = i+1) { | |
var tmp = original.charCodeAt(i); | |
if ((0xff0f < tmp) && (tmp < 0xff1a)) { | |
result += String.fromCharCode(tmp - 0xfee0); | |
} else { | |
result += String.fromCharCode(tmp); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment