first, the constructor function
New String (value)//constructor
function String (value)//Conversion functions
Second, the attribute
Length The number of characters in the string
var str = new String ("ABCDEFG"); document.write (str.length); Output 7
third, the method
1. Chatat () takes out a character in the specified position in a string.
New String ("ABCDEFG"); document.write (Str.charat (1)); // output B
2, Chatcodeat () returns the encoding of the character at the specified position in a string.
New String ("ABCDEFG"); document.write (Str.charcodeat (1)); // output 98
3, concat () concatenate one or more values into a string.
New String ("ABCDEFG"); var str1 = "Hijk"; document.write (Str.concat (str1)); // output Abcdefghijk
4. INDEXOF () looks for the position of a character or string in the specified string. If not found return-1
Syntax: indexOf (str) str: SUBSTRING or character
IndexOf (str,start) str: substring or character. Start: Specify where to start the search
New String ("ABCCBA"); document.write (Str.indexof (' B ')); // Output 1 document.write (str.lastindexof ("BC")); // Output 1
Use this method to implement the contains effect to determine whether a string contains another string:
<script type= "Text/javascript" > function () { var str1 = "Liu Bei"; var str2 = "Liu Bei is a bull man!" //if (Str2.indexof (STR1) >-1) {alert ("Included!") else {alert ("not included!") ); }} </script>
5. LASTINDEXOF () looks for the position of a character or string backwards (in reverse) in the specified string. If not found return-1
Syntax: lastIndexOf (str) str: SUBSTRING or character
LastIndexOf (str,start) str: substring or character. Start: Specify where to start the search
New String ("ABCCBA"); document.write (Str.lastindexof (' B ')); // output 4
6. Localecompare () compares strings using a locally defined order.
var str = "ABCCBA"; document.write (str.localecompare ("BC")); // output-1
7. Match () performs pattern matching using regular expressions.
8. Replace () performs a find and replace operation using a regular expression.
var str = "ABCCBA"; document.write (Str.replace ("B", "-")); // output A-CCBA
9. Search () finds strings in a string that match a regular expression.
var str = "ABCCBA"; document.write (Str.search ("B")); // Output 1
10, Slice () returns a slice or string of characters. If the argument is negative, the number from the back forward is indicated. Does not change the original string.
var str = "ABCDEFG"; // output CDEFG document.write (str); // output ABCDEFG You can see that the original string has not changed.
11, split () breaks with the specified delimiter string or regular expression, and returns an array of strings.
var str = "ABCDEFG"; var arr = str.split ("D"); document.write (Arr.join ()); // output ABC,EFG
12, substr () extracts a substring of a string, a variant of substring (). is deprecated.
13, substring () extracts a substring of a string.
Syntax: substring (start,end) starts from start and ends with end, including start but not end. Does not change the original string.
var str = "12345678"; document.write (str.substring (1,4)); // output 234
14, toLowerCase () returns a lowercase copy of the specified string.
var str = "AbcDEF"; document.write (Str.tolocalelowercase ()); // output abcdef
15, ToString () returns the original string value.
var str = "AbcDEF"; document.write (Str.tostring ()); // output AbcDEF
16, toUpperCase () returns an uppercase copy of the specified string.
var str = "AbcDEF"; document.write (Str.touppercase ()); // output ABCDEF
17, Trim () returns a copy of the specified string that is blank before and after the removal.
var str = " abcDEF "; document.write ("one" + str.trim () + "one" + "<br/>"); // output 11abcdef11 document.write ("one" + str + "one"); // output AbcDEF
18, ValueOf () returns the original string value.
var str = "AbcDEF"; document.write (Str.valueof ()); // output AbcDEF
A string of JavaScript