字符串ES6

\u{20BB7}  ;//𠮷,length:2

let s1='𠮷a';

s1.length;//3

s1.codePointAt(0);//134071

s1.codePointAt(0).toString(16);//20BB7

..

String.fromCharCode("0x20bb7");//ES5乱码

String.fromCodePoint("0x20bb7");//es6,𠮷

..

let str ='\u{20bb7}abc';

for(let i=0;i<str.length;i++){

  console.log(str[i])//乱码,乱码,a,b,c

}

for(let code of str){

  console.log(code)//𠮷,a,b,c

}

..

let str ='string';

str.includes('r')//true//字符串查找

str.startWith('str')//true 是否以str开始

str.endWith('ng')//true 是否以ng结束

str.repeat(2)//stringstring字符串重复即复制

..

let name='list';

let info='hello'

let m =`i am ${name} ${info}`;// i am list hello;//字符串模板

..

'1'.padStart(2,'0');//01 前补白,长度必须满足为2,长度不够最前方补0

'1'.padEnd(2,'0');//10 后补白

..

let user = {

  name:'list',

  info:'test'

}

console.log(abc`i am ${user.name},${user.info}`)//i am ,,,listtest

function abc(s,v1,v2){

  return s + v1 + v2

}

..

String.raw`hi/n3`//hi\n3;//斜杠不生效

 

posted @ 2017-12-18 10:54  树叶————  阅读(175)  评论(0)    收藏  举报