Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Loop and Split 1

Status
Not open for further replies.

TommyB44

Technical User
Jun 16, 2005
76
GB
Hi, All

Is there a way i can skip a split of a string with loop,
for example, if i had a string like this..

var s="?866?000?233?000?233?000";

could i use a loop like ( for(i=0;i<6;i++) ),
but instead of it increasing by 1 it increases by 2 ?.
So that it returns every "000".

Thanks for reading.
 
aahh yes, i mean s.split("?");
but every other "?" character so only the
"000"'s are returned as an Array.
 
Code:
        function test()
	{
	  var s="?866?000?233?000?233?000";
	  var arr = s.split("?");
	  arr.splice(0,1)
	  var newArr = new Array(0);
	  alert(arr.toString());
	  for(var i = 0; i<arr.length; i++)
	  {
		if(i % 2 != 0)
		{
			newArr.push(arr[i]);
		}
	  }
	  alert(newArr.toString());
	}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top