1

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 computer. Could someone please help me figure this out.

You can play around with my jsfiddle if you want... http://jsfiddle.net/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]);
    }
}
1
  • for(z = 0; z < mySplitResult2.length -1; i++) { you probably meant z++ there. Commented Oct 26, 2012 at 18:40

2 Answers 2

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(",");
Sign up to request clarification or add additional context in comments.

2 Comments

@StackOver: mySplitResult is an Array, so you just use typical array member access mySplitResult[i].split(",")
Do you know why it's doing this?
2

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.