Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Generating a list with 2 seperate variables ascending

    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

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is my suggestion.

    Code:
     
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •