"javascript function to convert utf8 string between fullwidth and halfwidth forms" Code Answer

4

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
By iGatiTech on May 17 2022

Answers related to “javascript function to convert utf8 string between fullwidth and halfwidth forms”

Only authorized users can answer the Search term. Please sign in first, or register a free account.