1、indexOf() 方法,返回字符串中指定文本首次出现的索引(位置),如果不存在该文本返回“-1”,第二个参数为检索开始的位置,直到结束位置。
var str = "The full name of China is the People's Republic of China.";
var pos = str.indexOf("China");//返回结果 17
2、lastIndexOf() 方法,返回指定文本在字符串中最后一次出现的索引(位置),如果不存在该文本返回“-1”,第二个参数为检索开始的位置,直到开始位置。
var str = "The full name of China is the People's Republic of China.";
var pos = str.lastIndexOf("China");//返回结果 51
3、search() 方法,返回字符串中指定文本首次出现的索引(位置),如果不存在该文本返回“-1”,支持正则表达式的查询。
var str = "The full name of China is the People's Republic of China.";
var pos = str.search("China");//返回结果 17
4、slice()方法,字符串的截取,第一个参数:起始索引(开始位置),第二个参数:终止索引(结束位置),包含第一个参数,不包含第二个参数,支持负数,如果为负数检索是从后往前。
var str = "The full name of China is the People's Republic of China.";
var pos = str.slice(1,5);//返回结果 he f
5、substring()方法,字符串的截取,第一个参数:起始索引(开始位置),第二个参数:终止索引(结束位置),包含第一个参数,不包含第二个参数。
var str = "The full name of China is the People's Republic of China.";
var pos = str.substring(1,5);//返回结果 he f
6、substr()方法,字符串的截取,第一个参数:起始索引(开始位置),第二个参数:截取的长度,如果没有该参数,截取到末尾。
var str = "The full name of China is the People's Republic of China.";
var pos = str.substr(1,5);//返回结果 he fu
7、replace()方法,用另一个值替换在字符串中指定的值,只替换第一个匹配值,不会改变调用它的字符串。它返回的是新字符串。
var str = "The full name of China is the People's Republic of China.";
var pos = str.replace('China','wegame');//返回结果 The full name of wegame is the People's Republic of China.
8、toUpperCase()方法,把字符串转换为大写。
var str = "China";
var pos = str.toUpperCase();//返回结果 CHINA
9、toLowerCase() 方法,把字符串转换为小写。
var str = "China";
var pos = str.toUpperCase();//返回结果 china
10、concat()方法,连接两个或多个字符串。
var str1= "Hello";
var str2= "World";
str3= str1.concat(" ",str2);//返回结果"Hello World"
11、trim() 方法,删除字符串两端的空白符。
var str = " Hello World! ";
var pos=str.trim();//返回结果"Hello World!"
12、charAt() 方法,返回字符串中指定下标(位置)的字符串
var str = "HELLO WORLD";
str.charAt(0); // 返回结果 H
13、charCodeAt() 方法,返回字符串中指定索引的字符 unicode 编码:
var str = "HELLO WORLD";
str.charCodeAt(0); // 返回 72