Is this possible? Find X And Replace With X+1

Help with writing and playing macros

Is this possible? Find X And Replace With X+1

Postby bjawnie » Tue Jan 10, 2006 7:27 pm

Hi,

I was looking for a way to increase the numbers in an array via UE and stumbled upon, for the very first time mind you, Macros.

This, to me, seemed to be the way to go, but even though I have the Regular Expression up and running there seems to be no way I can add 1 to the search result.

Let me give an example:

Code: Select all
Here we have some code which all of a sudden contains an array a_xml_content(2)



What I would like to do now is increase the array number so it turns out like this:
Code: Select all
Here we have some code which all of a sudden contains an array a_xml_content(3)




I thought this would be quite easy seeing how much else these macros are able to do. But no :\

I use the following Reg. Exp. to search for the array:

Code: Select all
a_xml_content(^(*^))


Yeah not even that is very precise but it seems to be close enough.



If any one would be able to lend a hand I would be very gratefull.


Cheers
bjawnie
User avatar
bjawnie
Newbie
 
Posts: 7
Joined: Sat Oct 29, 2005 11:00 pm

Re: Is this possible? Find X And Replace With X+1

Postby mrainey56 » Tue Jan 10, 2006 7:51 pm

The only way I know to do it is find the digit, then run a series of IfCharIs
checks on it - IfCharIs 3 then change it to a 4, etc.

Of course, this would get ugly if two or more digits might show up between the parentheses
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Is this possible? Find X And Replace With X+1

Postby bjawnie » Tue Jan 10, 2006 7:56 pm

Hi mrainey56,

Thanks for your prompt reply. Yeah I can see how that solution rapidly could result in quite a large Macro. Still I don't think the number will ever exceed 100 so it would be reasonable easy to mantain.

Might I persuade you into giving an example as I am a complete ignorant of all that is Macros.

Thanks


Cheers
bjawnie
User avatar
bjawnie
Newbie
 
Posts: 7
Joined: Sat Oct 29, 2005 11:00 pm

Re: Is this possible? Find X And Replace With X+1

Postby Mofi » Wed Jan 11, 2006 7:28 am

Because your example is similar to that one at viewtopic.php?t=2314 I could quickly modify and improve my macro according to your needs. This macro will work for numbers 0 - 198.

OverStrikeMode
ColumnModeOff
HexOff
UnixReOff
Loop
Find RegExp "a_xml_content([0-9]+)"
IfNotFound
ExitLoop
EndIf
Key LEFT ARROW
Key LEFT ARROW
IfCharIs "0"
"1"
Else
IfCharIs "1"
"2"
Else
IfCharIs "2"
"3"
Else
IfCharIs "3"
"4"
Else
IfCharIs "4"
"5"
Else
IfCharIs "5"
"6"
Else
IfCharIs "6"
"7"
Else
IfCharIs "7"
"8"
Else
IfCharIs "8"
"9"
Else
IfCharIs "9"
"0"
Key LEFT ARROW
Key LEFT ARROW
IfCharIs "("
InsertMode
Key RIGHT ARROW
"1"
OverStrikeMode
Else
IfCharIs "0"
"1"
Else
IfCharIs "1"
"2"
Else
IfCharIs "2"
"3"
Else
IfCharIs "3"
"4"
Else
IfCharIs "4"
"5"
Else
IfCharIs "5"
"6"
Else
IfCharIs "6"
"7"
Else
IfCharIs "7"
"8"
Else
IfCharIs "8"
"9"
Else
IfCharIs "9"
Key DEL
InsertMode
"10"
OverStrikeMode
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndLoop
InsertMode
UnixReOn

Remove the last red command, if you use regular expression in UltraEdit style by default instead of Unix style.
For UltraEdit v11.10c and lower see Advanced - Configuration - Find - Unix style Regular Expressions.
For UltraEdit v11.20 and higher see Advanced - Configuration - Searching - Unix style Regular Expressions.
Macro commands UnixReOn/UnixReOff modifies this setting.

And don't forget to enable the macro property Continue if a Find with Replace not found.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Is this possible? Find X And Replace With X+1

Postby bjawnie » Wed Jan 11, 2006 12:01 pm

Hi Mofi,

Excellent work. I really appreciate you taken off some time to help me out and then on top of that coming up with the correct code that works like a charm :)

Thanks
User avatar
bjawnie
Newbie
 
Posts: 7
Joined: Sat Oct 29, 2005 11:00 pm

Re: Is this possible? Find X And Replace With X+1

Postby mrainey56 » Wed Jan 11, 2006 1:28 pm

You're a good man Mofi.


Mike
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Is this possible? Find X And Replace With X+1

Postby Bego » Wed Jan 11, 2006 1:37 pm

You are right. But don't overpraise him. He might get lazy eventually ;-)))

rds
Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany


Return to Macros