JS:字符串对象
字符串API整理:
var str = 'hello';
concat():
var res = str.concat('wold','!!!');
substr():
var url = "http://www.baidu.com?username=admin&psw=123456";
var idx = url.indexOf('?');
var res1 = url.substr(idx+1); //从idx+1处开始
var res1 = url.suubstr(idx+1 , length)
//开始序号-结束序号,且不包含末尾序号位置
var res1 = url.slice(start,end);
//substring:开始序号-结束序号,且不包含末尾序号位置,并且支持:start>end,表示截取范围
var res1 = url.substring(start,end);
//区别
slice\substring\substr(start):默认都是从start到末尾
slice(负数):表示从末尾开始取值
replace():网站内容和谐
//replace()只替换一个
var res = str.replace(source,target);
//[1]
var index=0;
index = str.indexOf(source);
while(index!==-1){
}
//[2]
while(res =str.replace(source,target) !== null){
console.log(res);
str = res;
}
//replaceAll()
split():字符串分割
字符串无reverse();数组有!
String.fromCharCode() --相反-- str.charCodeAt()