Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  175] [ 5]  / answers: 1 / hits: 27366  / 11 Years ago, tue, december 10, 2013, 12:00:00

EDIT: Thanks to GOTO 0, I now know exactly what I my question is called.



I need a JavaScript function to convert from UTF-8 fullwidth form to halfwidth form.


More From » encoding

 Answers
14

Try this



function toASCII(chars) {
var ascii = '';
for(var i=0, l=chars.length; i<l; i++) {
var c = chars[i].charCodeAt(0);

// make sure we only convert half-full width char
if (c >= 0xFF00 && c <= 0xFFEF) {
c = 0xFF & (c + 0x20);
}

ascii += String.fromCharCode(c);
}

return ascii;
}

// example
toASCII(ABC); // returns 'ABC' 0x41

[#73828] Sunday, December 8, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mary

Total Points: 432
Total Questions: 98
Total Answers: 98

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;