JS Unicodeは、中国、Unicodeに中国、ASCIIにASCII転送のUnicode、Unicodeを回します

オンライン変換ツールhttps://oktools.net/unicode

中国を回しUNICODE

    関数decodeUnicode(STR){
        戻りアンエスケープ(str.replace(/ \\ U / GI、 '%U' ))
    }

 

Unicodeに中国

  
 関数encodeUnicode(STR){ 
        せたRES = [];
        以下のために(; iは<str.length; I = 0せiは++ ){ 
            RES [I] =( "00" + str.charCodeAt(I).toString(16))スライス(-4 
        } 
        戻り   "\\ U" + res.join( "\\ U" )。
    }

 

  

アスキーターンユニコード

関数A2U(STR){
     VAR予約= '' ; 
    のためのVAR ; I <str.length I ++は、I = 0 ){ 
        予約 + = '&#' + str.charCodeAt(I)+ ';' ; 
    } 
    戻り予約。
}

 

Unicodeのターンアスキー

関数U2A(STR){
     varが '='を予約VaRのコード= str.match(/&#(D +); / G); 
    場合(コード=== NULL ){
         戻りSTR。
    } 
    のためのVAR i = 0; iはcode.lengthを<; iは++ ){ 
        予約 + =に、String.fromCharCode(コード[I] .replace(/ [&#;] / G '' )); 
    } 
    戻り予約。
}

 

  

おすすめ

転載: www.cnblogs.com/vivec/p/11300941.html