 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
chandru155
Joined: 03 Dec 2008 Posts: 158 Location: chennai,india
|
Posted: Sun Oct 11, 2009 10:50 am Post subject: How to compare two strings in ifinstring |
|
|
Hi, i just want to use ifinstring to compare to strings.
Let MyString be a varibale. How to check whether MyString contains var1 or var2. I want to make a if loop.. How to i do this..
For comparing one, my code is like this
| Code: | ifinstring,MyString,var1
{
}
|
But how to use two strings(var1 and var2)
in C language, its like this
| Code: | if(c==var1 | c==var2)
{
} |
I knw, its not string.. |
|
| Back to top |
|
 |
Solar
Joined: 03 May 2009 Posts: 345 Location: OH, USA
|
Posted: Sun Oct 11, 2009 10:59 am Post subject: |
|
|
4 examples:
| Code: | If (InStr(MyString, var1) || InStr(MyString, var2))
MsgBox found var1 or var2 in MyString |
| Code: | If (InStr(MyString, var1))
MsgBox found var1 in MyString
Else If (InStr(MyString, var2))
MsgBox found var2 in MyString |
| Code: | IfInString, MyString, %var1%
MsgBox found var1 in MyString
Else IfInString, MyString, %var2%
MsgBox found var2 in MyString |
| chandru155 wrote: | in C language, its like this
| Code: | Code:
if(c==var1 | c==var2)
{
} |
|
Using exact match instead of "contains":
| Code: | If (MyString == var1 || MyString == var2)
MsgBox MyString equals var1 or var2 |
|
|
| Back to top |
|
 |
guest22 Guest
|
Posted: Sun Oct 11, 2009 1:17 pm Post subject: |
|
|
Besides using any of the code posted by Solar, you might consider using the If var in Matchlist command. It has the advantage (for many possible matches) of being much faster than InStr() in a loop.
| Code: | MatchList = one,two,three,four,five ; list of possible matches (may be made case sensitive)
var = two ; string to search for
if var in %MatchList%
msgbox, found "%var%"
else
msgbox, "%var%" not found
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|