if>string contains

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Scones
Junior Coder
Posts: 32
Joined: Fri Jul 05, 2019 11:21 am

if>string contains

Post by Scones » Mon Nov 18, 2019 11:52 am

Hi.

I want to make a formula that does this:

If string contains "this text" then do this.

This is my line atm.

If>DesiredChange=Inside dim

I'm basically looking for something to replace the "=" so it isn't 100% equal. I just want to know if the text appears in the string.

I tried using the * that works on things like window titles, but it doesn't seem to work here :)

Will regex be necessary?

Thanks in advance!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: if>string contains

Post by Dorian (MJT support) » Mon Nov 18, 2019 2:19 pm

Does something like the script below do what you need? It takes a string, in this case FishCatDog, and looks for Cat. If it finds Cat, it changes it to Horse. If it doesn't, nothing is changed.

Code: Select all

Let>MyString=FishCatDog

Pos>Cat,MyString,1,PosCat,

If>PosCat>1
  StringReplace>MyString,Cat,Horse,MyString
Endif

MessageModal>MyString
Yes, we have a Custom Scripting Service. Message me or go here

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

Re: if>string contains

Post by PepsiHog » Wed Nov 20, 2019 3:05 pm

@Scones,
Does this work for you?

Code: Select all

let>MyText=That darn cat keeps barking all night long.


let>FindThis=cat
RegEx>FindThis,MyText,0,match,nom,0


if>nom>0
   RegEx>FindThis,MyText,0,match,nom,1,dog,res
endif

mdl>%res%
Do you not like RegEx? You can skin a cat, including this one, in many ways.

Good Luck,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) 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
cron
Sign up to our newsletter for free automation tips, tricks & discounts