JS rich text encoding, decoding

 

// Switch to unicode encoding   
function encodeUnicode (STR) {
     var RES = [];
     for ( var I = 0; I <str.length; I ++ ) { 
        RES [I] = ( "00" + str.charCodeAt (I) . .toString (16)) Slice (-4 ); 
    } 
    return "\\ U" + res.join ( "\\ U" ); 
} 

// decode   
function decodeUnicode (STR) { 
    STR = str.replace (/ \ \ / G, "%" );
     // convert Chinese 
    str = unescape (str);
     // the other affected converted back to the original 
    str = str.replace (/% / G, "\\" );
     //Processing the URL links 
    STR = str.replace (/ \\ / G, "" );
     return STR; 
}

 

Guess you like

Origin www.cnblogs.com/xiaonangua/p/10944474.html