js转utf-8

    xiaoxiao2021-03-25  81

    function Utf8Encode(string) {      

    var utftext = "";      

    for(var n = 0; n < string.length; n++) {          

    var c = string.charCodeAt(n);          

    if(c < 128) {               utftext += String.fromCharCode(c);           } else if((c > 127) && (c < 2048)) {              

    utftext += String.fromCharCode((c >> 6) | 192);              

    utftext += String.fromCharCode((c & 63) | 128);          

    } else {              

    utftext += String.fromCharCode((c >> 12) | 224);              

    utftext += String.fromCharCode(((c >> 6) & 63) | 128);              

    utftext += String.fromCharCode((c & 63) | 128);          

    }      

    }      

    return utftext;   

    转载请注明原文地址: https://ju.6miu.com/read-22250.html

    最新回复(0)