SOLVED: Insert text string to front / end of each line in a text file

<< < (2/4) > >>

4wd:
Quote from: flowowery on July 22, 2012, 11:48:01 AM

One thing I am wondering, I wanted to complicate it a bit more, I want to do something different for each second line! Can either of these ways skip lines or do something different on each line, please tell me if either can? 

eg I have 2 links for each picture- 1st is large, second is small version. And I want this to happen.


HTTP.://IMG.1.LARGE.jpg
HTTP.://IMG.1.SMALL.jpg
HTTP.://IMG.2.LARGE.jpg
HTTP.://IMG.2.SMALL.jpg

<a href="HTTP.://IMG.1.LARGE.jpg" target="_blank">
<img src="HTTP.://IMG.1.SMALL.jpg"/>[/url]
<a href="HTTP.://IMG.2.LARGE.jpg" target="_blank">
<img src="HTTP.://IMG.2.SMALL.jpg"/>[/url]

Then I can just join each second line with the line before it. I found a vbs script to that.
 


Assuming that the thumbnail doesn't have the same name as the full size, (which logically it won't), just run two RegEx search/replace operations:


Formatted for Generic Code with the GeSHI Syntax Highlighter [copy or print]
Search: ^(.+LARGE\.jpg)$
Replace: <a href="\1" target="_blank">

followed by:


Formatted for Generic Code with the GeSHI Syntax Highlighter [copy or print]
Search: ^(.+SMALL\.jpg)$
Replace: <img src="\1"/></a>

NOTE: I'm only doing this in Notepad2-Mod, which only allows single line RegEx - other editors may allow multi-line RegEx in which case it could probably all be done in one RegEx operation, including the joining of the lines.

If the thumbnails were all the same size then conceivably you wouldn't need the ...SMALL... lines in the file at all, you just specify the height/width attributes of the img tag.

eg.


Formatted for Generic Code with the GeSHI Syntax Highlighter [copy or print]
Search: ^(.+LARGE\.jpg)$
Replace: <a href="\1" target="_blank"><img src="\1" height="42" width="42"/></a>

BAD: It means all the large images get loaded at once.
GOOD: Faster display when you click on a thumbnail since the images are already loaded.

BTW, you need to put URL stuff into a CODE box sometimes, the forum software sees [attach=1] and thinks it's a link and replaces it with [/URL].

flowowery:
Ok cool I get it, thanks for the code examples 4wd. I will try and keep all my uploads uniquely named enough so that they keep the "small" and "large" label- my quick tests now is keeping them. Will hunt for editors that do search replace by line if my labeling gets messed up during uploads. But sounds good if I can find an editor that will do the lot in one.

Was actually thinking might not be able to skip lines easily and thought of resorting to a macro, which would prob be messy where I cut the first line in notepad and paste into first line in a template scroll down a line, and repeat haha.


Oh yes the height and width, I noticed that when was looking for html tags but was curious about the resized smaller ones still loading full MB. That might be the easiest way to solve this, and means only one upload. Just need to work out how many "MB" loading in one page would be too much for the average users connection and then weigh it up. Thanks for the example of how to repeat it in one tag.


Thanks again for your help. Excited about these ideas now and going to do some experimenting to find the cruisiest method.

4wd:
Quote from: flowowery on July 22, 2012, 11:50:22 PM

I will try and keep all my uploads uniquely named enough so that they keep the "small" and "large" label- my quick tests now is keeping them.

It's not necessary to have them labelled "small"/"large", as long as there's a way to differentiate between the two is all that's required.

eg. All the images are in one folder and all the thumbnails are in another but the thumbnails have the same name as the full size images.

HTTP.://IMG.1.LARGE.jpg
HTTP.://thumbnail/IMG.1.LARGE.jpg
HTTP.://IMG.2.LARGE.jpg
HTTP.://thumbnail/IMG.2.LARGE.jpg


Formatted for Generic Code with the GeSHI Syntax Highlighter [copy or print]
Search: ^(.+//IMG.+)$
Replace: <a href="\1" target="_blank">

followed by:


Formatted for Generic Code with the GeSHI Syntax Highlighter [copy or print]
Search: ^(.+thumbnail.+)$
Replace: <img src="\1"/></a>

Addendum: Here's an online multi-line RegEx text editor.

And if you set it up like so:

[attachthumb=1]

Then click the RegExReplace button, (*), it will do what you want all in one hit :)

[attachthumb=2]

NOTE: They use $ instead of \ for specifying backreferences, eg. $1 i.l.o. \1

flowowery:
Hi, 4wd you are a great help and really good at that regexp, i made a lot of commands with it in my filemanager, but takes me a while to do them, and realised now if i haven't done it for a little while i forget everything..
That could be a neater way of keeping all the images also. Just thinking if label like that, I could just grab one link set and for each link repeat it twice for each tag and then add the extra bit for the thumbnail tag somehow, if I find regexp can do so.

Oh Just realized the images weren't loading, but got them loaded with IE. And cool. I see the new line part which I was messing with for something else while experimenting, but I didn't realize could use regexp to go through two lines and put together like that. I wouldn't have thought to see if I could do anything like that. I should be able to save a little bookmarklet form fill for this, making it even more breezy to get through.

Now I just need to get my images organized & really test this all out. Yay for no more copy pasting one by one! Thanks so so much. :D

JimboNWUK:
Hi I just came across this after coming back for a license key...

I wrote a small standalone app to do stuff like this precisely because I hate regexp and having to keep repeatedly experiment wit it to get it to do what I want. It's called Textreme and you can download it from my website at www.jollybean.co.uk

Let me know if you find it useful!

Regards,

Jim.

Navigation

[0] Message Index

[#] Next page

[*] Previous page