Using JavaScript to implement string splitting function

Source: Internet
Author: User
The string below is a reference fragment:
<title> String Segmentation </title>
<script language=javascript>
function Getmulti (OLDSTR) {
var newstr=oldstr;//field Contents
var i=0,j=0,t=1;//to determine whether there are multiple parts of the content
var foreindex;//records the position of the previous separator
var index,depchar;//records the current separator and its location
var linkstr= "";//Link mode
var astr = new Array (10);
var index1 = Newstr.indexof (",");
var index2 = Newstr.indexof (";");
var index3 = newstr.indexof ("%");
var index4 = Newstr.indexof (",");
var index5 = Newstr.indexof (";");
var index6 = Newstr.indexof ("");
function LTrim (str) {
for (var x=0; Str.charat (x) = ""; x + +);
Return str.substring (x,str.length);
}
if (index1!=-1) {
Index=index1;
Depchar= ",";
}
else if (index2!=-1) {
Index=index2;
Depchar= ";";
}
else if (index3!=-1) {
INDEX=INDEX3;
depchar= "%";
}
else if (index4!=-1) {
index=index4;
Depchar= ",";
}
else if (index5!=-1) {
INDEX=INDEX5;
Depchar= ";";
}
else if (index6!=-1) {
index=index6;
Depchar= "";
}
else{
T=0;index=-1;
Linkstr= "<a href=" to link the url ' target= ' BF ' > ' +newstr+ ' </a> ';
}
foreindex=0;
while (index!=-1) {
index = Newstr.indexof (Depchar, Foreindex);
if (index==foreindex) {foreindex=index+1;continue;}
if (index!=-1) {
Astr[j]=newstr.substring (Foreindex,index);
Astr[j]=ltrim (Astr[j]);
foreindex=index+1;
j=j+1;
}

}
Astr[j]=newstr.substring (Foreindex);
if (t==1)
{
for (i=0;i<j+1;i++)
{
linkstr=linkstr+ "<a href=" to link the url ' target= ' BF ' > ' +astr[i]+ ' </a> ';
}
}
return linkstr;
}
</script>
<body>
<script language=javascript>
var linkstring= "";
var tmpkeyword= "Programmer Software Management software development software complexity software maintenance software model software standard";
Linkstring=getmulti (Tmpkeyword);
document.write ("<font color= ' #006699 ' >" +linkstring+ ")
</script>
</body>
<ptml><pead><title> string Segmentation </title><script language=javascript>function Getmulti ( OLDSTR) {var newstr=oldstr;//field content var i=0,j=0,t=1;//to determine if there is more than one partial content Var foreindex;//record the position of the previous separator var index,depchar;// Record the current separator and its location var linkstr= "";//Link way var astr = new Array (10); var index1 = Newstr.indexof (","); var index2 = Newstr.indexof (";"); var index3 = newstr.indexof ("%"); var index4 = Newstr.indexof (","); var index5 = Newstr.indexof (";"); var index6 = Newstr.indexof (""); function LTrim (str) {for (Var x=0; Str.charat (x) = ""; x + +); Return str.substring (x,str.length); } if (index1!=-1) {index=index1; Depchar= ","; else if (index2!=-1) {index=index2; Depchar= ";";} else if (index3!=-1) {index=index3; depchar= "%"; else if (index4!=-1) {index=index4; Depchar= ","; else if (index5!=-1) {index=index5; Depchar= ";"; else if (index6!=-1) {index=index6; Depchar= "";} else{T=0;index=-1; Linkstr= "<a href=" to link the url ' target= ' BF ' > ' +newstr+ ' </a>"; } foreindex=0; while (index!=-1) {index = Newstr.indexof (Depchar, Foreindex); if (index==foreindex) {foreindex=index+1;continue;} if (index!=-1) {astr[j]=newstr.substring (foreindex,index); Astr[j]=ltrim (Astr[j]); foreindex=index+1; j=j+1; } astr[j]=newstr.substring (Foreindex); if (t==1) {for (i=0;i<j+1;i++) {linkstr=linkstr+ ' <a href= ' to link url ' target= ' BF ' > ' +astr[i]+ ' </a>  '; } return linkstr;} </script></pead><body><script language=javascript> var linkstring= ""; var tmpkeyword= "Programmer Software Management software development software complexity software maintenance software model software standard"; Linkstring=getmulti (Tmpkeyword); document.write ("<font color= ' #006699 ' >" +linkstring+ ") </script></body></ptml>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.