1. replace ()
Example:
<Script type = "text/javascript">
Var str = "this is text, and there is a text below, which is different from that text ";
Document. write (str. replace (/text/g, "test"); // converts all texts to test
Var str1 = "this is Text, and there is a Text below, which is different from that Text ";
Document. write (str1.replace (/text/gi, "test"); // converts all texts to test in case insensitive.
Var str2 = "this is text ";
Document. write (str2.replace (/text/, "test"); // convert text to test
Var str3 = "this is Text ";
Document. write (str3.replace (/text/I, "test"); // converts Text to test without case sensitivity.
</Script>
2. search ()
Example:
<Script type = "text/javascript">
Var str = "zhangqingyu ";
Document. write (str. search (/a/); -----> 2. If the string you want to search for does not exist,-1 is returned.
Var str1 = "zhAngqingyu ";
Document. write (str1.search (/a/); ---->-1, it does not exist
Document. write (str1.search (/a/I); ----> 2 this method is fuzzy query.
</Script>
3. slice () selects a part of the string to generate a new string
Example:
<Script type = "text/javascript>
Var str = "zhangqingyu ";
Document. write (str. slice (0, 2); ----> zh
Document. write (str. slice (-); ---> gyu. If the first parameter is negative, it starts to be a String Length + the first parameter
Document. write (str. slice (0,-4); ----> zhangqi, if the second parameter is negative, the end data is the string length + the second parameter
Document. write (str. slice (4); ------> gqingyu. If there is only one parameter, It is retrieved from the parameter until the end of the string.
</Script>
4. match () searches for the specified value from the string. It returns the specified value instead of the position of the specified value. It is different from search.
Example:
<Script type = "text/javascript>
Var str = "hello word! ";
Document. write (str. match ("word"); ---> word
Document. write (str. match ("Word"); ----> null
Document. write (str. match ("word! "); ----> Word!
</Scrip>
5. link () shows a string as a link.
Example:
<Script type = "text/javascript>
Var url = "Click here ";
Document. write (url. link ("http://www.hao123.com "));
</Script>
6. lastIndexOf () to obtain the position of the value to be queried in this string. If no value exists,-1 is returned.
Example:
<Script type = "text/javascript>
Var str = "zhangqingyu ";
Document. write (str. lastIndexOf ("g"); ----> 8
Document. write (str. lastIndexOf ("g", "1 "));
</Script>