Jump to content


IfInString:how to search for multiple needles in 1 haystack?


  • Please log in to reply
5 replies to this topic

#1 metalhead

metalhead
  • Guests

Posted 06 August 2012 - 11:34 AM

Hey, I have such a code:
IfInString, savedClip, `;
	Msgbox correct
IfInString, savedClip,`n
	Msgbox correct
Is there a way to group 2 needles together and search haystack once for occurrence of any of them?

#2 metalhead

metalhead
  • Guests

Posted 06 August 2012 - 11:38 AM

Also, is there a way to "Loop, parse" for `n or `;?

#3 Guests

  • Guests

Posted 06 August 2012 - 11:45 AM

If (InStr(var,"string) or InStr(var,"otherstring"))
or

Checks whether a variable's contents match one of the items in a list.
Source: http://www.autohotke...mmands/IfIn.htm



#4 metalhead

metalhead
  • Guests

Posted 06 August 2012 - 12:17 PM

thanks!
I had errors with IfInStr about illegal character because I forgot to take the needle into quotation marks.

And what about Loop?
I need loop to parse a string, search either for "`;" or for "`n" (in my case I have items separated either with `; or with `n, so they can't be combined in 1 string).
So I could do so:
IfInString, savedClip, `;
   separator = `;
IfInString, savedClip,`n
   separator = `n
Is it possible to do later something like this?
Loop, Parse, savedClip, %separator%

Edit: just read an article about loop,parse and decided to follow the manual's advice there:
StringReplace, savedClip, savedClip, `n, ¢
StringReplace, savedClip, savedClip, `;, ¢
Loop, Parse, savedClip, ¢


#5 MasterFocus

MasterFocus
  • Moderators
  • 4126 posts

Posted 06 August 2012 - 05:28 PM

Here's something you can do:
Delim := ""
If [color=#0000FF]it has `n in it[/color]
    Delim .= "`n"
If [color=#0000FF]it has ; in it[/color]
    Delim .= ";"

[color=#0000FF]And then use all delimiters stored in Delim as explained here:
http://www.autohotkey.com/docs/commands/LoopParse.htm[/color]


#6 sinkfaze

sinkfaze
  • Moderators
  • 6086 posts

Posted 06 August 2012 - 09:33 PM

if RegExMatch(savedClip,";|`n",delim)