admin管理员组文章数量:1410682
I am trying to break up this string by first splitting it into sections divided by ';'. Then I want to split those sections divided by ','. It is not working though and I am about to break my puter. Could someone please help me figure this out.
You can play around with my jsfiddle if you want... /
var myString = "Call 1-877-968-7762 to initiate your leave.,-30,0,through;You are eligible to receive 50% pay.,0,365,through;Your leave will be unpaid.,365,0,After;";
var mySplitResult = myString.split(";");
for(i = 0; i < mySplitResult.length -1; i++){
var mySplitResult2 = i.split(",");
for(z = 0; z < mySplitResult2.length -1; i++) {
//document.write("<br /> Element " + i + " = " + mySplitResult[i]);
document.write("<br/>Element" + z + " = " + mySplitResult[z]);
}
}
I am trying to break up this string by first splitting it into sections divided by ';'. Then I want to split those sections divided by ','. It is not working though and I am about to break my puter. Could someone please help me figure this out.
You can play around with my jsfiddle if you want... http://jsfiddle/ChaZz/
var myString = "Call 1-877-968-7762 to initiate your leave.,-30,0,through;You are eligible to receive 50% pay.,0,365,through;Your leave will be unpaid.,365,0,After;";
var mySplitResult = myString.split(";");
for(i = 0; i < mySplitResult.length -1; i++){
var mySplitResult2 = i.split(",");
for(z = 0; z < mySplitResult2.length -1; i++) {
//document.write("<br /> Element " + i + " = " + mySplitResult[i]);
document.write("<br/>Element" + z + " = " + mySplitResult[z]);
}
}
Share
Improve this question
asked Oct 26, 2012 at 18:29
John DoeJohn Doe
2,0709 gold badges33 silver badges54 bronze badges
1
-
for(z = 0; z < mySplitResult2.length -1; i++) {
you probably meantz++
there. – jbabey Commented Oct 26, 2012 at 18:40
2 Answers
Reset to default 5i
is a number, as that's how you defined it.
To split the string, you need to access the i
member of the Array.
var mySplitResult2 = mySplitResult[i].split(",");
If I may, if you have to split with character a
then character b
, the simplest would be :
string.split('a').join('b').split('b')
本文标签: htmlSplitting string 2 times with javascriptStack Overflow
版权声明:本文标题:html - Splitting string 2 times with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744926501a2632630.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论