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')
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744926502a4601468.html
评论列表(0条)