Capitalize only in specified columns

Find, replace, find in files, replace in files, regular expressions

Capitalize only in specified columns

Postby HolySpirit » Mon Oct 10, 2005 3:01 pm

Hi,
I've got 2 questions regarding regular expression.
The first is:

How can I transform a text like
asdfgh qwertz
sdfgerfhhjkjk dhgkjdk

to
Asdfgh Qwertz
Sdfgerfhhjkjk Dhgkjdk
(The first letter after a blank should become a capital)

The second question is:

How can I transform the text
qwert-asdfg
asdfgh - sjhdfgshf

to
asdfg-qwert
sjhdfgshf - asdfgh
(Exchanging the two sides of '-')

Any help would be greatly appreciated :-)
Regards from Vienna as well :-)

HolySpirit
User avatar
HolySpirit
Newbie
 
Posts: 3
Joined: Sun Oct 09, 2005 11:00 pm

Re: Capitalize only in specified columns

Postby mrainey56 » Mon Oct 10, 2005 6:12 pm

Question 1. A macro solution, will be slow on a large file. Make sure you have an empty line at the end of the file, or it won't know when to stop. It upper cases the first character in each line and the first character following each space.

InsertMode
ColumnModeOff
HexOff
UnixReOn
Top
ToUpper
Loop
Key DOWN ARROW
IfEof
ExitLoop
EndIf
ToUpper
EndLoop
Top
Loop
Find " "
IfEof
ExitLoop
EndIf
EndSelect
Key RIGHT ARROW
Key LEFT ARROW
ToUpper
Key HOME
Key DOWN ARROW
EndLoop


Question 2. a regex search and replace - fast

Regular Expressions checked
Unix-style regular expressions (see configuration)

Find What: (.+)( *)-( *)(.+)
Replace With: \4\2-\3\1
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Capitalize only in specified columns

Postby HolySpirit » Tue Oct 11, 2005 1:39 am

Thank you, it worked fine, but I've got to precise my question :oops: .

For both cases:
Search-replace should occur only for the marked columns :oops:

Best regards from Vienna
Holy Spirit
User avatar
HolySpirit
Newbie
 
Posts: 3
Joined: Sun Oct 09, 2005 11:00 pm

Re: Capitalize only in specified columns

Postby mrainey56 » Tue Oct 11, 2005 10:49 am

You'll have to furnish truly representative before/after samples before anybody can help.
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Capitalize only in specified columns

Postby HolySpirit » Tue Oct 11, 2005 10:59 am

Ok, sorry for that :oops:

The text
aaaaaaaaaaaa asdfgh qwertz
aaaaaaaaaaaa sdfgerfhhjkjk dhgkjdk

should be transformed to


aaaaaaaaaaaa Asdfgh Qwertz
aaaaaaaaaaaa Sdfgerfhhjkjk Dhgkjdk

And the text

aaaaaaaaaaaa qwert-asdfg
aaaaaaaaaaaa asdfgh - sjhdfgshf

to
aaaaaaaaaaaa asdfg-qwert
aaaaaaaaaaaa sjhdfgshf - asdfgh
(Exchanging the two sides of '-')

Thanks a lot in advance
Best regards
Holy Spirit
User avatar
HolySpirit
Newbie
 
Posts: 3
Joined: Sun Oct 09, 2005 11:00 pm

Re: Capitalize only in specified columns

Postby mrainey56 » Tue Oct 11, 2005 3:51 pm

Try these.

Question 1.

InsertMode
ColumnModeOff
HexOff
UnixReOn
Top
Loop
Find RegExp "^[a]+ [a-z]"
IfNotFound
ExitLoop
EndIf
EndSelect
Key LEFT ARROW
ToUpper
Find " "
EndSelect
Key RIGHT ARROW
Key LEFT ARROW
ToUpper
EndLoop



Question 2.

Regular Expressions checked
Unix-style regular expressions (see configuration)

For some reason it doesn't change the first line. Open up a blank line at the top of your file before the search/replace. Also have a blank line at the end.


Find What: (^[a]+ )(.+)( *)-( *)(.+)
Replace With:\1\5\3-\4\2
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina


Return to Find/Replace/Regular Expressions