html - Splitting string 2 times with javascript - Stack Overflow

I am trying to break up this string by first splitting it into sections divided by ';'.Then

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 meant z++ there. – jbabey Commented Oct 26, 2012 at 18:40
Add a ment  | 

2 Answers 2

Reset to default 5

i 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

相关推荐

  • html - Splitting string 2 times with javascript - Stack Overflow

    I am trying to break up this string by first splitting it into sections divided by ';'.Then

    2天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信