Macroscheduler guide shows me the following:
Simple expressions can contain only two parts separated by one of the following operators:
= Equals
> Greater than
< Less than
<> Not Equal
Is there an operator to determine if one variable is contained within another variable?
For example, let x=abcdefg let y= dg
I require the result to show that both the letters 'd' and 'g' are contained in the variable x
Find variable contained within another variable
Moderators: Dorian (MJT support), JRL
-
- Newbie
- Posts: 4
- Joined: Sat May 30, 2015 4:44 pm
- Location: PORT ORANGE, FL USA
Re: Find variable contained within another variable
Hi, I am not aware of any such operator, however you can easily set up a subroutine that does the same:
Code: Select all
Let>x=abcdefg
Let>y=dg
Gosub>match,y,x,result
mdl>result
SRT>match
//SRT to match y in x and return true/false in third input variable
Let>LOCALVARS=1
Let>y=match_VAR_1
Let>x=match_VAR_2
Let>var_out=match_VAR_3
RegEx>.,y,0,m1,nm1,0
If>nm1>0
Let>flag=true
Else>
Let>flag=false
Endif
Let>ct=0
While>ct<nm1
Add>ct,1
RegEx>m1_%ct%,x,0,m2,nm2,0
If>nm2=0
Let>flag=false
Endif
EndWhile
Let>LOCALVARS=0
Let>%var_out%=flag
END>match
Re: Find variable contained within another variable
Hi, previous version matched irrespective of case. I added a fourth parameter 1/0 where you can choose if case sensitive or not (ie should y=dG match or not. If case sensitive, then no, otherwise yes)
Code: Select all
Let>x=abcdefg
Let>y=dg
Gosub>match,y,x,result,0
mdl>result
SRT>match
//SRT to match y in x and return true/false in third input variable
//Fourth input variable indicates if case sensitive or not 1/0
Let>LOCALVARS=1
Let>y=match_VAR_1
Let>x=match_VAR_2
Let>var_out=match_VAR_3
Let>case_ind=match_VAR_4
RegEx>.,y,0,m1,nm1,0
If>nm1>0
Let>flag=true
Else>
Let>flag=false
Endif
Let>ct=0
While>ct<nm1
Add>ct,1
If>case_ind=1
Let>tmp=m1_%ct%
Let>tmp0=(?-i)%tmp%
Else
Let>tmp0=m1_%ct%
Endif
RegEx>tmp0,x,0,m2,nm2,0
If>nm2=0
Let>flag=false
Endif
EndWhile
Let>LOCALVARS=0
Let>%var_out%=flag
END>match
-
- Newbie
- Posts: 4
- Joined: Sat May 30, 2015 4:44 pm
- Location: PORT ORANGE, FL USA
Re: Find variable contained within another variable
Thank you for pointing me to Regular Expressions in your code.
Masterful answer!
Masterful answer!