If "variable" contains specific text

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

If "variable" contains specific text

Post by Dominic_Fichera » Tue Oct 07, 2014 2:21 am

Hey guys,

How can I write an if statement to see if a variable CONTAINS a specific piece of text? It doesn't have to be equal to it, it just has to contain it. For example, the strings might all be numbers, but I only want to execute a command if the number contains a number 1 in it, so the number could be 1, 10, 14, 21, 101 etc.

Hope this makes sense :)

Kind regards,

Dominic Fichera

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

Re: If "variable" contains specific text

Post by Marcus Tettmar » Tue Oct 07, 2014 9:01 am

Use the Position function. Like this:

Code: Select all

Pos>substring,variable,1,posText
If>posText>0
  //variable contains substring
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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