• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

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.
0
Daniele Brunengo
Asked:
Daniele Brunengo
  • 3
  • 2
  • 2
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
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 MVEDeveloperCommented:
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
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aikimarkCommented:
Notepad++ has macros you can record and might have an editable macro language that could do this.
0
 
Scott Fell, EE MVEDeveloperCommented:
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now