How do I make textpad do this?

General questions about using TextPad

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

Post Reply
dedotno1
Posts: 1
Joined: Sat Apr 24, 2010 2:04 am

How do I make textpad do this?

Post by dedotno1 »

Hi,
I just downloaded Textpad this morning.


Let's say that I have this 3 words in Textpad:

word #1

word #2

word #3

…

word #100


I want to make it like down below (adding a coma for word 2 until word #100):

word #1

, word #2

, word #3

, …

, word #100


How do I do this kind of stuff using Textpad? I used the search function in this forum but I could not find a solution.

Regards,

dedotno1
ACRobin
Posts: 134
Joined: Fri Nov 04, 2005 9:51 pm
Location: Northumberland,UK
Contact:

Post by ACRobin »

Several ways to do what you want.
run a regular expression to insert the comma from the 2nd line down - you could then automate this process by recording a macro and assigning to a keystroke if it is something you may do a large number of times.

you can put the editor in block mode and select the first column and "Fill" the first column with a comma.

you can just record a macro and insert the comma without a regular expression.

you need to get used to the editor and how to select text/find replace/use regular expressions - the help is good.
gan

Post by gan »

You can make a simple search and replace using regular expression.

Search for:

Code: Select all

\n^([A-Za-z].*)$
and replace with:

Code: Select all

\n,\1
This will work if the line contains an actual word so it start with a letter. It will not insert a comma in front of the first word if the first word start at line 1 and it will not add a comma for empty lines if you have any blank lines inbetween. If your lines might contain something that is not a actual words like start with a number, with a space or a special characters you have to change it a bit to work correctly.

You can also make this into a macro for later use like ACRobin said.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

gan's solution assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Here's a slightly simpler version:
Find what: \n([A-Za-z])
Replace with: \n, \1

[X] Regular expression

Replace All
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

If you just run the RegEx on the whole document, then all lines will be processed, not stopping after line 100.

So you may need tp select words 1-100 or make the macro select the hundred words and have the macro run on Selected text only.

Or. run the Regex on the complete document, then go back and remove the commas from every hundredth word.
Hope this was helpful.............good luck,
Bob
ACRobin
Posts: 134
Joined: Fri Nov 04, 2005 9:51 pm
Location: Northumberland,UK
Contact:

Post by ACRobin »

Not sure why this thread moved to "Regular Expressions" as you can provide a solution to the original question without using "Regex".

Not everyone wants to use Regex especially if the only way they use it is by posting to a forum to get a solution and blindly using it.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I'm inclined to agree. The trouble with a regular expression topic in a support forum of this type is that it's solution-oriented rather than problem-oriented. Users who post head messages here usually have a problem, not a solution.
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

"Some people, when confronted with a problem, think 'I know, I’ll use regular expressions.' Now they have two problems." --Jamie Zawinski
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

:-)

http://regex.info/blog/2006-09-15/247
(from the blog of Jeffrey Friedl, the Mastering Regular Expressions man)
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

I find it funny that ACRobin's solutions were using RegEx, but then later states:
you can provide a solution to the original question without using "Regex".
:wink:
Hope this was helpful.............good luck,
Bob
Post Reply