Function: indexof ()
Function: returns the subscript of the first character matching the substring in a string.
CopyCode The Code is as follows: var mystring = "JavaScript ";
VaR W = mystring. indexof ("v"); W will be 2
VaR x = mystring. indexof ("S"); X will be 4
Var y = mystring. indexof ("script"); y will also be 4
VaR z = mystring. indexof ("key"); Z will be-1
Function: Split ()
Function: uses a specified separator to split a string and store it in an array.Copy codeCode: Str = "JPG | BMP | GIF | ICO | PNG ";
Arr = thestring. Split ("| ");
// Arr is an array containing character values "jpg", "BMP", "GIF", "ICO", and "PNG"
Function: Join ()
Function: combines an array into a string var delimitedstring = myarray. Join (delimiter) using the separator you selected );Copy codeCode: var delimitedstring = myarray. Join (delimiter );
VaR mylist = new array ("jpg", "BMP", "GIF", "ICO", "PNG ");
VaR portablelist = mylist. Join ("| ");
// The result is JPG | BMP | GIF | ICO | PNG.
Functions: slice () and substring ()
Slice and substring can both accept one or two parameters. The 1st parameters are used to obtain the starting position of the string to be truncated, if the first parameter is not null, it is the first digit in the end position of the string to be truncated (that is, the obtained end position is not in the return value ), if it is null, It is truncated to the last character of the entire string. Copy code The Code is as follows: <script language = "JavaScript">
VaR stmp = "rcinn.cn ";
// Use a parameter
Alert (stmp. Slice (3); // starts from 4th characters and truncates to the last character. "nn.cn" is returned"
Alert (stmp. substring (3); // starts from 4th characters and truncates to the last character. "nn.cn" is returned"
// Use two parameters
Alert (stmp. Slice (2nd) // starts from 5th characters and ends with characters. "Cinn" is returned"
Alert (stmp. substring (2nd); // starts from 5th characters and ends with characters. "Cinn" is returned"
// If only one parameter is used and the value is 0, the whole parameter is returned.
Alert (stmp. Slice (0); // returns the entire string
Alert (stmp. substring (0); // returns the entire string
// How can we reverse the first character? Other functions can be used. If you must use these two methods, set the first parameter to 0 and the second parameter to 1, see the following example.
Alert (stmp. Slice (0, 1); // return "R"
Alert (stmp. substring (0, 1); // return "R"
// In the preceding example, we can see that slice () and substring () have the same usage and return the same value, but when the parameter is negative, their return values are different. Let's look at the example below.
Alert (stmp. Slice (2,-5); // return "I"
Alert (stmp. substring (2,-5); // return "RC"
// From the above two examples, we can see that slice (2,-5) is actually slice (2, 3), and the negative 5 is converted into 3; and substring (2,-5) it is actually substring (), and the negative number is converted to 0. swubstring always uses the minimum number as the starting position.
</SCRIPT>
Note: The number of digits of a string starts from 0.