Find / replace on CR/LF in TextPad

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
jenguin777
Posts: 3
Joined: Wed Jan 11, 2012 1:39 pm

Find / replace on CR/LF in TextPad

Post by jenguin777 »

Hi, hoping someone can help me.

I cannot figure out how to turn this:

111-11-1111
222-22-2222
333-33-3333

into this:

'111-11-1111','222-22-2222','333-33-3333'

in TextPad 5.4.2.

I used to have UltraEdit32 on my old machine and that allowed you to do a find on CR/LF (Hex 0D0A) and replace with space. Then you could do a find on space and replace with ',' (single quote, comma, single quote) but I don't have UltraEdit32 on my new machine and I cannot figure out a way to do this in TextPad. The Hex search in TextPad doesn’t appear to work. You select the Hex radio button and enter 0D0A and it looks for that literal string even with the Hex radio button selected.

Any suggestions? This is something I need to do a lot.

Thanks!!
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

You can represent a newline (CR/LF) by \n provided you also select Regular expression, so you can replicate the steps you used to do in UltraEdit32. But an easier way is as follows.

First, in Configure > Preferences > Editor, enable POSIX regular expression syntax.

Then do a Replace operation with these settings:

Find what: (.*)\n
Replace with: '\1',

Select Regular expression and click Replace All. Then delete the final comma.
jenguin777
Posts: 3
Joined: Wed Jan 11, 2012 1:39 pm

Post by jenguin777 »

Thanks very much!! Your solution works great with one small exception. The single quotes don't get put around the last number:

'111-11-1111','222-22-2222','333-33-3333',444-44-4444

Any idea how my replace pattern can be modified so that the last number is also enclosed with the single quotes? I'd like for it to look like:

'111-11-1111','222-22-2222','333-33-3333','444-44-4444'

Thanks again for your help!!

Jen
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

Make sure the file ends in a blank line and try it again.
jenguin777
Posts: 3
Joined: Wed Jan 11, 2012 1:39 pm

Post by jenguin777 »

Awesome, that worked perfectly...you rock!

Thanks,

Jen
Post Reply