Why this string compare doesn't work Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Why this string compare doesn't work

08 Aug 2020, 11:55

Code: Select all

var := "today-xyz"
test := strsplit(var, "-").2 
;msgbox, % test
if (test != "xyz") || (test != "fff")
{
	MsgBox, xyz ; why is this msgbox showing if it does = xyz
}
else
{
msgbox, ignore
}

ExitApp
gregster
Posts: 9020
Joined: 30 Sep 2013, 06:48

Re: Why this string compare doesn't work  Topic is solved

08 Aug 2020, 12:02

why is this msgbox showing if it does = xyz
You are using or (||) - so (test != "fff") will evaluate to true, if var is xyz, because it's not fff.
Because you use or, that's enough to make the whole expression true.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Why this string compare doesn't work

08 Aug 2020, 12:28

gregster wrote:
08 Aug 2020, 12:02
why is this msgbox showing if it does = xyz
You are using or (||) - so (test != "fff") will evaluate to true, if var is xyz, because it's not fff.
Because you use or, that's enough to make the whole expression true.
thanks I changed it to &&

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww and 282 guests