1 Reply Latest reply on Jul 9, 2014 5:24 AM by Steve Werner

    List a Range

    creativejoan0425 Level 1

      I want to alert the text to 11,12,13,14,15,3,3,4,5,20,21,22,23,24,25

      but the result is 11,12,13,14,15, 11,12,13,14,15, 11,12,13,14,15,3-5, 20-25

       

      here is my Script:

      var myText = "11-15, 3, 3-5, 20-25";

      var mySplitText = myText.split(", ");

      myRangeList ="";

      var myHyphenSearch = mySplitText.toString().search(/-/g);;

      //alert(myHyphenSearch);

      if(mySplitText.content = "-"){

      for(var k=0; mySplitText.length>k; k++){

      var patt = new RegExp(/ \d*-/i);

      var res = patt.exec(myText);

       

       

      var myFI = Number(mySplitText.toString().indexOf(res));

      var myMI=Number(mySplitText.toString().indexOf("-"));

      var myLI=Number(mySplitText.toString().indexOf(",", "-"));

       

       

      var myFirstDigit = mySplitText.toString().substring(myFI, myMI);

      var myLastDigit = mySplitText.toString().substring(myMI+1, myLI);

       

       

      for(var i=myFirstDigit; myLastDigit>=i; i++){

          myRangeList += i+",";

          }//end of for Loop

      var myRestText = mySplitText.toString().substring(myLI);

      var myNewText = myRangeList+myRestText;

      var myNewTextString = myNewText.replace(/,,/g,",");

          }//end of for Loop

      alert(myNewTextString);

        }