Replacing Paragraph Marker

General questions about using TextPad

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

Post Reply
User avatar
diek
Posts: 20
Joined: Thu Mar 27, 2003 3:35 pm

Replacing Paragraph Marker

Post by diek »

Hi,
I did not think this would be difficult, but it was difficult for me. How do I replace a paragraph marker^p with " ^p? I ended up using another text editor but I want to use Textpad. I would appreciate any guidance,
D
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Remember that TextPad is a text editor. There is no such thing as a paragraph marker in plain text (unless you mean the paragraph sign: ¶ or §). Do you mean the markers at the ends of paragraphs in a word processing document produced by a program such as Microsoft Word? MS Word allows you to search for these markers using the idiosyncratic pattern ^p. If you save a Word document as a plain text file, you will find that the ends of paragraphs are converted into end-of-line markers (by default on a PC, a pair of characters: <CR> (carriage return), <LF> (line feed)). End-of-line markers are often called, generically, new lines.

You can search for new lines in TextPad using regular expressions. You can use any of the patterns ^, $ or \n. The patterns ^ and $ are anchors; that is, they match at a new line without matching any characters. ^ matches at the beginning of a line; $ matches at the end of a line. So if you replace either of them with something, that something replaces no characters; it is just inserted. The pattern \n matches the new line itself; so if you replace it with something, that something replaces the new line. Thus you can remove new lines, joining adjacent lines together.

It is not clear from your message exactly what you are trying to do. But if you want to insert a double quote at the end of each line, you can use Search | Replace:
Find what: $
Replace with: "

[x] Regular expression
User avatar
diek
Posts: 20
Joined: Thu Mar 27, 2003 3:35 pm

Great Explanation

Post by diek »

Ben,
Thank you. That worked perfectly. I asked this question because I came across an interesting process to find empty folders.
DIR /AD/B/S | SORT /R > EMPTIES.BAT

The resulting file required adding RD" to the beginning and " to the end. The article from PCMag, http://www.pcmag.com/article2/0,1759,805015,00.asp suggested:
'using Find and Replace to search for ^p (which represents the paragraph mark) and replace it with "^pRD " '

Have a great day,
d
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

The following assumes you are using POSIX regular expression syntax:
Configuration | Preferences | Editor
[x] Use POSIX regular expression syntax
Using Search | Replace:
Find what: (.+)
Replace with: rd "\1"

[x] Regular expression
This works because matches are leftmost (in this case, each match begins at the beginning of a line) and longest (in this case, each match ends at the end of a line). The use of + rather than * causes the pattern not to match empty lines.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

And ben_josephs' double quotes also take care of long name issues with spaces that might otherwise fail.
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Diek had already improved on the version in PCMag's rather poor article by adding quotes. That article is not the most helpful. It suggests that the user should use MS Word to edit a text file. Wouldn't encourage me to read (far less, buy) the magazine...

To clarify my explanation above:
Find what: (.+)
Replace with: rd "\1"
is equivalent to
Find what: ^(.+)$
Replace with: rd "\1"
User avatar
diek
Posts: 20
Joined: Thu Mar 27, 2003 3:35 pm

Stuff

Post by diek »

I have to say I truly appreciate everyone's help. I am going to go test. I love Textpad, it saves me so much time that I wouldn't be able to begin to count all the hours!
Post Reply