Replace each number with number+5

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

Replace each number with number+5

Postby heool » Sat Aug 19, 2006 4:01 am

hello!

I'm try to find a way to replace some numbers in .xml files!

Example: <Location top="5563" left="1192" bottom="5685" right="1244"/>

replace to: <Location top="5563" left="1192" bottom="5690" right="1249"/>


how to do it? thanks!
User avatar
heool
Newbie
 
Posts: 2
Joined: Fri Aug 18, 2006 11:00 pm

Re: Replace each number with number+5

Postby Mofi » Sat Aug 19, 2006 8:11 am

You need 2 macros for this job. The first one which you must create first is my universal submacro CountUp which is posted at counter ?

After you have created the submacro CountUp, create the main macro for your individual usage which needs the macro property Continue if a Find with Replace not found enabled.

The code for the main macro is:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Clipboard 7
Top
Loop
Find RegExp "bottom="[0-9]+""
IfNotFound
ExitLoop
EndIf
EndSelect
Key LEFT ARROW
StartSelect
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Copy
PlayMacro 1 "CountUp"
SelectWord
PlayMacro 1 "CountUp"
SelectWord
PlayMacro 1 "CountUp"
SelectWord
PlayMacro 1 "CountUp"
SelectWord
PlayMacro 1 "CountUp"
EndLoop
Top
Loop
Find RegExp "right="[0-9]+""
IfNotFound
ExitLoop
EndIf
EndSelect
Key LEFT ARROW
SelectWord
Copy
PlayMacro 1 "CountUp"
SelectWord
PlayMacro 1 "CountUp"
SelectWord
PlayMacro 1 "CountUp"
SelectWord
PlayMacro 1 "CountUp"
SelectWord
PlayMacro 1 "CountUp"
EndLoop
Top
ClearClipboard
Clipboard 0

Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.

Edited macro on 2006-08-20:

Replaced

StartSelect
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW
Key LEFT ARROW

with the single command SelectWord because the macro should work for all numbers not only for numbers with 4 digits.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4068
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Replace each number with number+5

Postby heool » Sun Aug 20, 2006 12:45 am

thanks a lot! I try it now...
User avatar
heool
Newbie
 
Posts: 2
Joined: Fri Aug 18, 2006 11:00 pm


Return to Find/Replace/Regular Expressions