IF command with strings
andreponzoni
I would like to know how to use the IF command to check string variables, to do something like this:
string Svar
IF ( Svar=="ABC" )
// do this
Else
// do that
EndIf
IF ( Svar=="ABC" )
// do this
Else
// do that
EndIf
I know it is a silly question, and should have a simple solution.. but I've been stuck with this for a long while, and I have found just examples with numeric variables.
Thanks
Andre
January 29, 2015 at 03:05 am - Permalink
I will take a look! Thanks!
January 29, 2015 at 03:10 am - Permalink
if (cmpstr(str, "ABC") == 0)
//do this
else
//do this
endif
I would not use "svar" as string name, because SVAR is used as global string declaration.
January 29, 2015 at 03:11 am - Permalink
The name of the variable was just an example.. but well reminded!
Thanks you all!
Andre
January 29, 2015 at 03:26 am - Permalink
stringmatch
for this use. The help page for stringmatch lists a few other useful string handling functions.January 29, 2015 at 05:42 am - Permalink
string tstr
strswitch(tstr)
case "Hello":
print "got hello"
break
case "Goodbye":
print "ciao"
break
default:
print "Input Hello or Goodbye only"
break
endswitch
return 0
end
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
January 29, 2015 at 10:12 am - Permalink
GrepString
,which would allow you to match all of "abc1", "abc2", "abc3" using "abc"
(or even "abc\d{1}")
February 5, 2015 at 01:17 am - Permalink
SelectString
comes in handy.February 5, 2015 at 01:24 am - Permalink