if contains problem code example included Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
AHKStudent
Posts: 314
Joined: 05 May 2018, 12:23

if contains problem code example included

20 Jul 2018, 18:31

See in my code here, I just want to check if the line contains a word, but it does not work

Code: Select all

dummytext =
(
first line
second line
third line
forth line
)

Loop, parse, dummytext, `n, `r
{

      if (A_LoopField contains "second") ; if I change this to: if (A_LoopField = "second line") everything works
      {
         continue
      }
   tlines%A_Index% := A_LoopField 
   thevars .= "tlines" A_Index " = " tlines%A_Index% "`n"
   tht = %a_index%
}

MsgBox, %thevars% `n total loops %tht%
ExitApp
User avatar
gregster
Posts: 1495
Joined: 30 Sep 2013, 06:48

Re: if contains problem code example included  Topic is solved

20 Jul 2018, 18:37

Well, the docs say, contains is not supported in expressions. Hence, I guess, the () with If won't work. But you don't need it. And of course, the Matchlist takes "s literally. So...

Code: Select all

dummytext =
(
first line
second line
third line
forth line
)

Loop, parse, dummytext, `n, `r
{

      if A_LoopField contains second ; if I change this to: if (A_LoopField = "second line") everything works
      {
         continue
      }
   tlines%A_Index% := A_LoopField 
   thevars .= "tlines" A_Index " = " tlines%A_Index% "`n"
   tht = %a_index%
}

MsgBox, %thevars% `n total loops %tht%
ExitApp
User avatar
gregster
Posts: 1495
Joined: 30 Sep 2013, 06:48

Re: if contains problem code example included

20 Jul 2018, 18:55

You are welcome!
I just noticed that if the last line of the dummytext contains second, this last iteration won't be counted for the total loops (because Continue will end the loop in this case, before the tht variable can be updated... you could probably move this last line of the loop to the beginning of the loop in order to fix that (if it is important).

Return to “Ask For Help”

Who is online

Users browsing this forum: 2X7W, buzstringer, swagfag, Xtra and 91 guests