Suppose the string to be split is: s= "... fs...fs ..." where FS represents the character or string to be delimited.
Definitions and usage
The split () method is used to split a string into an array of strings.
Grammar
Stringobject.split (Separator,howmany)
Instance 1
The code is as follows |
Copy Code |
var ss=s.split ("FS"); for (Var i=0;i<ss.length;i++) { Handle each ss[i]; } |
Instance 2
In this case, we'll split the more complex string of structures:
The code is as follows |
Copy Code |
"2:3:4:5". Split (":")//will return ["2", "3", "4", "5"] "|a|b|c". Split ("|")//will return ["", "a", "B", "C"] |
Instance 3
The code is as follows |
Copy Code |
<script type= "Text/javascript" > var str = "1234"; var str1 = "Basketball, volleyball, table tennis"; var arr = str.split ("");//All Split var arr1 = Str1.split (",");//split by comma var arr2 = Str1.split (",", 2);//divide by comma, keep two paragraphs </script> |
We can test it out locally.
Instance 3
The code is as follows |
Copy Code |
<input id= "x" type= "text"/> <input type= "button" onclick= "x ()" Value= "Enter mail address, get username"/> <script> function X () { var X=document.getelementbyid ("X"). value.tostring (); var c=x.split ("@"); document.getElementById ("x"). Value=c[0]; } </script>
|
And we'll come up with a VBScript approach.
Below in ASP VBScript:
The code is as follows |
Copy Code |
Dim ss Ss=split (S, "FS") For I=lbound (ss) To UBound (ss) |
Process each SS (i)
Next
Note: LBound (ss) should be 0, if split fails, UBound return-1
Note: If an empty string ("") is used as a separator, then each character in the Stringobject is split.
Summary: The split function is much like what we used to do in PHP and the ASP character segmentation function, it as long as what the split line can be the content we want to split the group.