Page 1 of 1

Find / replace on CR/LF in TextPad

Posted: Wed Jan 11, 2012 1:46 pm
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!!

Posted: Wed Jan 11, 2012 2:29 pm
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.

Posted: Wed Jan 11, 2012 3:51 pm
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

Posted: Wed Jan 11, 2012 4:02 pm
by ak47wong
Make sure the file ends in a blank line and try it again.

Posted: Wed Jan 11, 2012 4:27 pm
by jenguin777
Awesome, that worked perfectly...you rock!

Thanks,

Jen