Page 1 of 1

IfInString help

Posted: 04 Dec 2017, 11:26
by HIAC
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?

Re: IfInString help

Posted: 04 Dec 2017, 12:02
by boiler
No it shouldn't. It doesn't contain "NotApple". You are thinking of it backwards.

Re: IfInString help

Posted: 04 Dec 2017, 12:08
by HIAC
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?

Re: IfInString help

Posted: 04 Dec 2017, 12:13
by boiler
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.

Re: IfInString help

Posted: 04 Dec 2017, 12:15
by HIAC
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..

Re: IfInString help

Posted: 04 Dec 2017, 12:17
by boiler
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.

Re: IfInString help

Posted: 04 Dec 2017, 12:18
by HIAC
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?

Re: IfInString help

Posted: 04 Dec 2017, 12:20
by boiler
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.

Re: IfInString help

Posted: 04 Dec 2017, 12:23
by HIAC
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:

Re: IfInString help

Posted: 04 Dec 2017, 14:14
by boiler
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