For the cutting of the string of the usual use may not be particularly many, and the relatively thin, so self-self-examination. Prepared
Since all before a demo test, if there is a wrong, please understand. Some of the remaining properties find time to continue adding.
1. Function: Split ()
Function: To store a string partition into an array using a specified delimiter
Example: str= "Jpg|bmp|gif|ico|png"; Arr=str.split ("|");
Arr is an array that contains the character values "JPG", "BMP", "GIF", "ico", and "PNG"
2. Function: Join ()
Function: Merges an array into a string using the separator of your choice
Example: 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.
3. Function: Concat ()
Function: To connect two arrays together;
Example: arr1=[1,2,3,4]
arr2=[5,6,7,8]
Alert (Arr1.concat (ARR2))//result is [1,2,3,4,5,6,7,8]
4. Function: CharAt ()
Function: Returns the character at the specified position. The subscript for the first character in the string is 0. If the argument index is not between 0 and String.Length, the method returns an empty string.
Example: Var str= ' a,g,i,d,o,v,w,d,k,p '
Alert (Str.charat (2))//Result G
5: Function: charCodeAt ()
Function: The charCodeAt () method returns the Unicode encoding of the character at the specified position. This return value is an integer between 0-65535.
The method charCodeAt () is similar to the operation performed by the CharAt () method, except that the former returns the encoding of the character at the specified position, and the latter returns a string of characters subcode.
Example: Var str= ' a,g,i,d,o,v,w,d,k,p '
Alert (Str.charcodeat (2))//result is 103. That is, G's Unicode code is 103.
6. Function: Slice ()
Function: Arrayobject.slice (start,end)
Start: Required. Specify where to start the selection. If it is a negative number, then it sets the position from the end of the array. In other words,-1 refers to the last element, 2 to the penultimate element, and so on.
End: Optional. Specify where to end the selection. The parameter is the array subscript at the end of the array fragment. If this argument is not specified, the Shard array contains all the elements from start to the end of the array. If this argument is a negative number, it sets the element that starts at the end of the array.
Returns a new array containing the elements in the arrayobject from start to end (excluding the element).
Example: Var str= ' AHJI3O3S4E6P8A0SDEWQDASJ '
Alert (Str.slice (2,5))//Results Ji3
7. Function: substring ()
The definition and Usage substring method is used to extract characters from a string mediation between two specified subscripts.
Grammar stringobject.substring (Start,stop)
Start Required. A non-negative integer that stipulates the position of the first character of the substring to be extracted in the stringobject.
Stop is optional. A non-negative integer that is 1 more than the last character of the substring to extract in the Stringobject.
If this argument is omitted, the returned substring continues to the end of the string.
Returns a new string that contains a substring of stringobject with all characters from the start to the stop-1, whose length is stop minus start. Description The substring returned by the substring method includes the character at start, but does not include the character at the end. If start is equal to end, then the method returns an empty string (that is, a length of 0). If start is larger than end, the method swaps the two parameters before extracting the substring. If start or end is a negative number, it is replaced with 0.
Example: Var str= ' AHJI3O3S4E6P8A0SDEWQDASJ '
Alert (str.substring (2,6))//Result Ji3o3
8. Function: substr
The definition and Usage substr method returns a substring of the specified length starting at the specified position.
Syntax Stringobject.substr (start [, length])
Parameter start required. The starting position of the desired substring. The index of the first character in the string is 0.
Length is optional. The number of characters that should be included in the returned substring. Note If length is 0 or negative, an empty string is returned. If this argument is not specified, the substring continues to the end of the stringobject.
Example: var str = "0123456789";
Alert (str.substring (0));------------"0123456789"
Alert (str.substring (5));------------"56789"
alert (str.substring);-----------""
alert (str.substring);-----------""
Alert (str.substring ( -5));-----------"0123456789"
Alert (str.substring ( -10));----------"0123456789"
Alert (str.substring ( -12));----------"0123456789"
Alert (str.substring (0,5));----------"01234"
Alert (str.substring (0,10));---------"0123456789"
Alert (str.substring (0,12));---------"0123456789"
Alert (str.substring (2,0));----------"01"
Alert (str.substring (2,2));----------""
Alert (str.substring (2,5));----------"234"
Alert (str.substring (2,12));---------"23456789"
Alert (str.substring (2,-2));---------"01"
Alert (str.substring ( -1,5));---------"01234"
Alert (str.substring ( -1,-5));--------""
The difference between substr and substring methods
<script type= "Text/javascript" > var str = "0123456789";/alert (str.substring (0));//------------"0123456789" al ERT (Str.substring (5));//------------"56789" alert (str.substring);//-----------"" Alert (str.substring (12));// -----------"" Alert (str.substring ( -5));//-----------"0123456789" alert (str.substring ( -10));//----------"
0123456789 "Alert (str.substring ( -12));//----------" 0123456789 "alert (str.substring (0,5));//----------" 01234 " Alert (str.substring (0,10));//---------"0123456789" alert (str.substring (0,12));//---------"0123456789" alert ( Str.substring (2,0))//----------"(Str.substring (2,2));//----------" "Alert (str.substring (2,5));//------ ----"234" alert (2,12);//---------"23456789" alert (str.substring);---------"Alert" ( Str.substring ( -1,5))//---------"01234" alert (str.substring ( -1,-5));//--------"" Alert (STR.SUBSTR (0));//-------- -------"0123456789" Alert (STR.SUBSTR (5));//---------------"56789" alert (str.substr);//--------------"alert (str.substr);//--------------" "Alert (Str.substr ( -5));//--------------" 0123456789 "alert ( Str.substr ( -10))//-------------"0123456789" alert (STR.SUBSTR ( -12));//-------------"0123456789" alert (str.substr (0,5)); /-------------"01234" alert (STR.SUBSTR (0,10));//------------"0123456789" alert (str.substr);//------------" 0123456789 "alert (str.substr 2,0);//-------------" "Alert (Str.substr (2,2));//-------------" "" Alert "str.substr ( 2,5))//-------------"23456" alert (STR.SUBSTR (2,12));//------------"23456789" alert (str.substr);//-------- ----"" Alert (Str.substr ( -1,5));//------------"01234" alert (STR.SUBSTR ( -1,-5));//-----------"" </script>