AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to compare two strings in ifinstring

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
chandru155



Joined: 03 Dec 2008
Posts: 158
Location: chennai,india

PostPosted: Sun Oct 11, 2009 10:50 am    Post subject: How to compare two strings in ifinstring Reply with quote

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
View user's profile Send private message Yahoo Messenger
Solar



Joined: 03 May 2009
Posts: 345
Location: OH, USA

PostPosted: Sun Oct 11, 2009 10:59 am    Post subject: Reply with quote

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
View user's profile Send private message
guest22
Guest





PostPosted: Sun Oct 11, 2009 1:17 pm    Post subject: Reply with quote

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
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group