...

View Full Version : Generating a list with 2 seperate variables ascending



Zuton
02-03-2004, 11:37 PM
Sorry if this is in an innapropriate forum, probably not even the right messageboard, but to be honest I wasn't sure what this would fall under and I'm totaly stumped.

This place seems to be full with talented intelligent individuals, so hopefully someone can come up with a solution to this little teaser.

Say for instance I had a line of code like this -

texttext texttext 01.jpg texttext texttext01

and i wanted to generate a list of 50 or more of those, where the next lines would be -

texttext texttext 02.jpg texttext texttext02
texttext texttext 03.jpg texttext texttext03
texttext texttext 04.jpg texttext texttext04

etc etc

I've tried programs which can change one of the variables, but not both.

Hopefully it's something really simple I can use

Thanks in advance

Garadon
02-04-2004, 12:38 AM
Here is my suggestion.



textReplace('texttext texttext (*).jpg texttext texttext(*)',0,50,2);

function textReplace(aText,aFrom,aToo,aConstantSize)
{
var I=aText.indexOf('(*)');
if(I!=-1)
{
var devided=aText.split('(*)');
var P;
for(j=aFrom;j<aToo+1;j++)
{aText="";
for(i=0;i<devided.length-1;i++)
{
P=''+j;
aText=aText+devided[i];
while(P.length<aConstantSize)
{
P='0'+''+P;
}
aText=aText+P;
}
aText=aText+devided[devided.length-1];

document.writeln(aText+'<br>');
}
}
}


textReplace('texttext texttext (*).jpg texttext texttext(*)',0,50,2);
1st argurment in the string is the text to insert in, please note (*) these are the ones that gets inserted at
2nd and 3rd argument is the interval the number range runs in.
4th argument is the forced length of the insertion number.

this code should in theor be able to replace all occurences of (*) in a string up



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum