Suggestion / Request

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
PepsiHog
Automation Wizard
Posts: 513
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Suggestion / Request

Post by PepsiHog » Mon Oct 31, 2011 3:59 am

I love the command StringReplace. It's very simple and powerful. But I would like to see an addition to this command. How many times it should replace the string.

The current way is:

let>example=The apple is red. The sky is blue.
StringReplace>example,is,was,example

This returns:
The apple was red. The sky was blue.

What I'd like to see is:
let>example=The apple is red. The sky is blue.
StringReplace>example,is,was,example,1

Notice the addition of ",1" at the end of StringReplace.

This would indicate to replace only the first found string.

So your result would be:
The apple was red. The sky is blue.

This ofcourse is a very basic example. You may have a string of numbers and want to remove the first number that repeats more than once in the whole number. Such as 283628. You could replace the first, but not the second.

Also maybe to make it even more flexible add a START_AT_POS variable.
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Mon Oct 31, 2011 5:55 pm

Here is a method to study.

Code: Select all

//replace only first instance of pattern in string

Let>text=The apple is red. The sky is blue.
Let>pattern=....(is)....
RegEx>pattern,text,0,matches,num,0
StringReplace>matches_1,is,was,r2
Let>pattern=%matches_1%
RegEx>pattern,text,0,matches,num,1,r2,r
MessageModal>r

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Oct 31, 2011 6:47 pm

For just the first match:

Let>text=The apple is red. The sky is blue.
Let>pattern=^(.*?)is
RegEx>pattern,text,0,matches,nm,1,$1was,new_text
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Mon Oct 31, 2011 7:36 pm

Very clever with the $1 syntax -- however I could find no mention
of this in my help file!

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Mon Oct 31, 2011 10:57 pm

Hi adroege,
adroege wrote:Very clever with the $1 syntax -- however I could find no mention
of this in my help file!
That's probably because its a RegEx thing... not a Macro Scheduler thing.
For examples, try a Google search for $1 against the forums and you'll get some interesting and relevant posts like these:

Capture group in RegEx?!
Converting capital letters to small letters

...and there are lots more... all from the forums... the "help file that writes itself".

Take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
PepsiHog
Automation Wizard
Posts: 513
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Thanks

Post by PepsiHog » Tue Nov 01, 2011 2:50 am

Thanks everyone.

I didn't know. Knowing is half the battle. G.I. Joe.
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
PepsiHog
Automation Wizard
Posts: 513
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

On a side note

Post by PepsiHog » Tue Nov 01, 2011 1:06 pm

Just looked up RegEx on the web.

On a side note.....

I don't know what you people be smoking!!!!

But it MUST be DAMN GOOD!!!

Where can I get some of that?
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts