How can I repeat a block of text n times, changing only a number (counter) inside each iteration of the block?

Hello, I was wondering if there is a fast way to repeat a block of text/code a given number of times, changing only a number inside it with a counter. I need to do this very often when I write html, for instance:

<div>
<a class="pp_content" href="media/category3/main/04.jpg" title="Descrizione opzionale"><img src="media/category3/thumb/04.jpg"/></a>
</div>

<div>
<a class="pp_content" href="media/category3/main/05.jpg" title="Descrizione opzionale"><img src="media/category3/thumb/05.jpg"/></a>
</div>
.
.
.

<div>
<a class="pp_content" href="media/category3/main/XX.jpg" title="Descrizione opzionale"><img src="media/category3/thumb/XX.jpg"/></a>
</div>

Open in new window


So I was wondering, is there any software able to do this? Is it possible with Notepad++ and macros?

Thanks guys.
Daniele BrunengoIT Consultant, Web DesignerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
http://jsbin.com/lirih/1/
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  <script>
    $(function(){
var img;
for (i = 0; i < 25; i++) { 
  if (i < 10){ // pad a zero
    img = '0'+i;
  }else{
    img = i;
  }
var data = '<div><a class="pp_content" href="media/category3/main/'+img+'.jpg" title="Descrizione opzionale"><img src="media/category3/thumb/05.jpg"/></a></div>';
$('#results').append(data);
}
});  
  </script>
  <meta charset="utf-8">
  <title>padas</title>
</head>
<body>
  <div id="results"></div>
</body>
</html>

Open in new window

0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Forgot the other img
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  <script>
    $(function(){
var img;
for (i = 0; i < 25; i++) { 
  if (i < 10){ // pad a zero
    img = '0'+i;
  }else{
    img = i;
  }
var data = '<div><a class="pp_content" href="media/category3/main/'+img+'.jpg" title="Descrizione opzionale"><img src="media/category3/thumb/'+img+'.jpg"/></a></div>';
$('#results').append(data);
}
});  
  </script>
  <meta charset="utf-8">
  <title>padas</title>
</head>
<body>
  <div id="results"></div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Daniele BrunengoIT Consultant, Web DesignerAuthor Commented:
Thanks, though I was hoping there would be a desktop software able to create the lines.

I actually need a software to do this for me offline, the html has to be static and not created by a script.
I guess my question was badly formulated, this is not my mother language after all.

I managed with Excel though, copy pasting Excel output to Notepad++.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

aikimarkCommented:
Notepad++ has macros you can record and might have an editable macro language that could do this.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Actually, a long time ago I used to use excel for this very thing.  I would simply make col A the first part, col B then variable and col C the last part and Col D a concatenation of A,B,C.  

B3 could be =B2+1 then drag all columns down to what you need.  Then copy just the very last row for column D and paste.

I didn't have the understanding of scripting back then.  Today I would simply do this in vbs, php or JS/Jquery.  

The beauty of doing this in scripting is if you need to make a change, it's only changing in one spot.
0
aikimarkCommented:
XSLT might also be a reasonable solution path.  Heck.  Most any scripting or programming language will do this kind of thing.
0
Daniele BrunengoIT Consultant, Web DesignerAuthor Commented:
Yes, that's how I did it with Excel. I've tried out your jquery script too, it works great although it's not what I initially had in mind. So I'll accept your answer and close the question, since I now have 2 ways to do this. Also, didn't know jack about XSLT, so thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.