js --- 中字符串与unicode编码

 1、charAt():把字符串分成每一个字符,从左往右提取指定位置的字符

var str = '天气';
alert( str.charAt(1) );            //气

2、charCodeAt ():在第一个的基础上,返回的是字符的unicode编码

var str = '天气';
 
alert( str.charCodeAt(0) );        //22825

3、String.fromCharCode():通过编码值在unicode编码库中查找出对应的字符。

alert( String.fromCharCode(22825, 27668) );            //天气

4、当两个字符串进行大小比较时,比的是第一个字符的unicode编码的大小:

alert( 'abbbbb' > 'b' );                //unicode编码中a<b,所以是false;
alert( '10000' > '2' );                 //unicode编码中1<2,所以是false;

  

猜你喜欢

转载自www.cnblogs.com/yuerdong/p/10172877.html