1. Character Method Charat (), charCodeAt (), fromCharCode ()
Copy Code code as follows:
var stringvalue = "Hello World";
Alert (Stringvalue.charat (1)); E
Alert (stringvalue[1]); E
Alert (Stringvalue.charcodeat (1)); 101
Alert (String.fromCharCode (104,101)); "He"
2. Return substring method Slice (), substr (), substring ()
Slice (), substring () method The first parameter specifies the starting position of the substring, the second parameter specifies the settlement position (excluding the end position), and the original string is unchanged
SUBSTR () The second parameter refers to the number of characters returned, the original string is unchanged
Copy Code code as follows:
var stringvalue = "Hello World";
Alert (Stringvalue.slice (3)); "Lo World"
Alert (stringvalue.substring (3)); "Lo World"
Alert (STRINGVALUE.SUBSTR (3)); "Lo World"
Alert (Stringvalue.slice (3,7)); "Lo W"
Alert (stringvalue.subtring (3,7)); "Lo W"
Alert (STRINGVALUE.SUBSTR (3,7)); "Lo worl"
Alert (Stringvalue.slice (-3)); "Rld", take the last 3 characters of the array
Alert (Stringvalue.slice (-3)); "Rld", take the last 3 characters of the array
3. String position method IndexOf () and LastIndexOf ()
The IndexOf () method searches the substring from the back, receives a parameter or two parameters, the first parameter specifies the substring to search for, and the second parameter specifies to search backwards from that location, not to find the return-1
The LastIndexOf () method searches for a substring from the back and receives a parameter or two arguments, the first parameter specifies the substring to search for, and the second parameter specifies that a forward search from that location is not found, return-1
Copy Code code as follows:
var stringvalue = "Hello World";
Alert (Stringvalue.indexof ("O")); 4
Alert (Stringvalue.lastindexof ("O")); 7
Alert (Stringvalue.indexof ("O", 6)); 7
Alert (Stringvalue.lastindexof ("O", 6)); 4
4. String capitalization conversion method toLowerCase () and toUpperCase ()
Convert toLowerCase () to lowercase, touppercase () to uppercase
5. Comparison of Strings Localecompare ()
Localecompare () can be compared in English, can also compare Chinese, uppercase letters in the first lowercase letter in the back
6. String sorting:
Copy Code code as follows:
var stringvalue= ["China", "Nan nan", "Jun Jun"];
Alert (Stringvalue.sort (Stringcompare));
//Ascending sort function-A-Z
function Stringcompare (value1,value2) {
return value1.localecompare (value2);//Descending z-a, Value1 and value2 interchange locations
}