IfInString help

Get help with using AutoHotkey and its commands and hotkeys
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

IfInString help

04 Dec 2017, 11:26

Hello :)

config.ini :
  • Apple
    Banana

    Code: Select all

    A := "NotApple"
    
    IniRead, List, config.ini, LIST
    IfInString, List, %A%
    {
    	MsgBox Ok.
    }
    "NotApple" should also trigger MsgBox as it contains "Apple" in it, but it doesn't do.. how can I modify this to work?
Last edited by HIAC on 04 Dec 2017, 12:20, edited 1 time in total.
User avatar
boiler
Posts: 3437
Joined: 21 Dec 2014, 02:44

Re: IfInString help

04 Dec 2017, 12:02

No it shouldn't. It doesn't contain "NotApple". You are thinking of it backwards.
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: IfInString help

04 Dec 2017, 12:08

boiler wrote:No it shouldn't. It doesn't contain "NotApple". You are thinking of it backwards.
So what would be the code to do so?
User avatar
boiler
Posts: 3437
Joined: 21 Dec 2014, 02:44

Re: IfInString help

04 Dec 2017, 12:13

You break your list into an array, then loop through the array and check each item to see if it's in the string in your variable A. You're checking to see if the string in your variable A is in the list, which it is not.
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: IfInString help

04 Dec 2017, 12:15

boiler wrote:You break your list into an array, then loop through the array and check each item to see if it's in the string in your variable A. You're checking to see if the string in your variable A is in the list, which it is not.
Do you understand that I need it to popup the MsgBox like this? I may not be using the right code..
User avatar
boiler
Posts: 3437
Joined: 21 Dec 2014, 02:44

Re: IfInString help

04 Dec 2017, 12:17

Yes, you can have it do whatever you want when it finds it. It's the part that finds it that you need to change, not the MsgBox.
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: IfInString help

04 Dec 2017, 12:18

boiler wrote:Yes, you can have it do whatever you want when it finds it. It's the part that finds it that you need to change, not the MsgBox.
Exactly, so do you know what should I change it to?
User avatar
boiler
Posts: 3437
Joined: 21 Dec 2014, 02:44

Re: IfInString help

04 Dec 2017, 12:20

I just described it above. You need to break your list into an array. You can use StrSplit() to do that. Then you loop through them and check to see if each element is contained in your variable.
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: IfInString help

04 Dec 2017, 12:23

boiler wrote:I just described it above. You need to break your list into an array. You can use StrSplit() to do that. Then you loop through them and check to see if each element is contained in your variable.
And I don't know how exactly to do that.. :eh:
User avatar
boiler
Posts: 3437
Joined: 21 Dec 2014, 02:44

Re: IfInString help

04 Dec 2017, 14:14

From your other posts on the forum, it seems like you want to write scripts, not just have them written for you, so I was trying to give you enough info to let you know what to do and let you try it yourself first.

Code: Select all

A := "NotApple"
IniRead, List, config.ini, LIST
ListItems := StrSplit(LIST, "`n", "`r")
For Key, Item in ListItems
	If InStr(A, Item)
		MsgBox, % "Item " Item " appears in " A

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot] and 343 guests