方法一:charAt():返回在指定位置的字符
var str = 'nihaome wozhendexiangxeuhaoqianduan'
var str2 = str.charAt(4);
var str3 = str.charAt(25);
var str4 = str.charAt(5,26);
console.log(str2);
console.log(str3);
console.log(str4);
方法二:charCodeAt():返回咋指定位置的字符的Unicode编码
var str = "llinihao mezaigama";
var str2 = str.charCodeAt(5);
var str3 = str.charCodeAt(3);
console.log(str3);
console.log(str2);
方法三:conca():连接字符串
var str1 = "lixiaoqi";
var str2 = 'zaijian';
console.log(str2.concat(str1));
方法四: indexOf(): 检索字符串,返回的是字符在字符串的下标
var str1 = "lixiaoqi";
var num1 = str1.indexOf('o');
var num2 = str1.indexOf('lllll');
var num3 = str1.indexOf('ni');
console.log(num1);
console.log(num2);
console.log(num3);
方法五:match():在字符串内检索指定的值或找到一个或多个正则表达式的匹配,返回的是值而不是值的位置。
var str1 = "lixiaoqi";
var str2 = str1.match('iao');
var str3 = str1.match('lll');
console.log(str2);
console.log(str3);
方法六:replace():替换匹配的字符串
var str1 = "nihaome";
var str2 = "lixiaoqi";
var str3 = str1.replace(str1.match('hao'),str2.match('lixi'));
console.log(str3);
方法七:search():检索与字符串匹配的子串,返回的是地址
var str1 = "lixiaoqi nihaoya zaiganma";
var str2 = "nihaoya";
var str3 = "wobuzai";
var num1 = str1.search(str2);
var num2 = str1.search(str3);
console.log(num1);
console.log(num2);
方法8:slice():提取字符串片段,并在新的字符串中返回被提取的部分
var str1 = 'nihaoya wobuhaoya'
console.log(str1.slice(4,9));
console.log(str1.slice(2,14));
console.log(str1);
console.log(str1.slice(-1,0));
console.log(str1.slice(30,100));
console.log(str1.slice(-1,10));
方法9:split():把字符分割成数组
var str1 = "nihao-zaijian-dajiahao";
console.log(str1.split(''));
var str2 = str1.split('-');
console.log(str2);
console.log(str1);
方法10:toLocaleLowerCase():把字符串转换成小写
var str = "NIHAOME WOHENHAOnizaiganmane";
console.log(str.toLocaleLowerCase());
var str1 = str.toLocaleLowerCase();
console.log('-----------');
console.log(str1);
console.log(str);
方法11:toLocaleUpperCase():把字符串准换成大写
var str = "deawwWWEzaiganmane";
console.log(str.toLocaleUpperCase());
var str1 = str.toLocaleUpperCase();
console.log('-----------');
console.log(str1);
console.log(str);
方法12:toLowerCase():把字符串转换成小写
var str = "deawwWWEzaiganmane";
console.log(str.toLowerCase());
var str1 = str.toLowerCase();
console.log('-----------');
console.log(str1);
console.log(str);
方法13:toUpperCase():把字符串转换成大写
var str = "deawwWWEzaiganmane";
console.log(str.toUpperCase());
var str1 = str.toUpperCase();
console.log('-----------');
console.log(str1);
console.log(str);
方法14:substr():从起始索引号提取字符串中指定书目的字符
var str = "nihaoya wohenhao dajiahao"
var str3 = str.substr(3,19);
console.log(str3);
方法15:subString():提取字符串中两个指定索引号之间的字符
var str = "nihaoya wohenhao dajiahao"
var str3 = str.substring(3,19);
var str4 = str.substr(3,19);
console.log(str4);
console.log('-------------');
console.log(str3);