Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Strange results with character string compares



  • Please log in to reply
3 replies to this topic
otlaolap
  • Members
  • 43 posts
  • Last active: Sep 12 2013 02:33 AM
  • Joined: 15 Aug 2007

In an AHK_L script (unicode 64-bit) I cannot make sense of the following results taken from a much larger script (and annotated here)

If (NewWindTubes <> RunWinTubes)
  OutputDebug NOT EQUAL ; Shows as NOT EQUAL even though I believe the strings to be equal
If (NewWindTubes = RunWinTubes) 
  OutputDebug ARE EQUAL ; does not show as equal
OutputDebug, % StrLen(RunWindTubes) . " " . StrLen(NewWindTubes) ; Shows as 74 74 (i.e. both are 74)
asdf := StrLen(RunWindTubes)
Loop, %asdf%
{
AA := SubStr(RunWindTubes, A_Index, 1)
BB := SubStr(NewWindTubes, A_Index, 1)
If (AA <> BB)
  OutputDebug, %A_Index% [%AA%][%BB%] ; this never shows
If (AA = BB)
  OutputDebug, %A_Index% [%AA%][%BB%] EQUAL ; this shows 74 equal results
}
NewWindTubes := "<4> [0 2560 0 1600] [3760 5680 0 1200] [-1200 0 0 1600] [2560 3760 0 1600]" ; the actual data
RunWindTubes := "<4> [0 2560 0 1600] [3760 5680 0 1200] [-1200 0 0 1600] [2560 3760 0 1600]" ; the actual data 
If (NewWindTubes <> RunWinTubes)
  OutputDebug NOT EQUAL ; shows NOT EQUAL even though the typed values above are identical
If (NewWindTubes = RunWinTubes)
  OutputDebug ARE EQUAL 
AAA := NewWindTubes
BBB := RunWindTubes
If (AAA = BBB)
  OutputDebug ARE EQUAL ; shows ARE EQUAL
If (AAA <> BBB)
  OutputDebug NOT EQUAL
Return                           

What I think I am seeing are equal strings being reported as not equal even though every character in them, on a character by character basis, compares as euqal, and even though, if the strings are assigned to different variables, the different variables compare as equal.  But I know I make errors, and do not see them.  One of the variables, RunWindTubes, is global; I tried making the other global as well (it had been local) but got the same result.  I cannot make them both local, because the strings being compared are captured in different routines at different times.

 

Any insight?



MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
I haven't gotten into the mysteries of Unicode. But I would start with StringCaseSense and '==' operator instead of just using '=' and see if you get different results. Other than that perhaps someone Unicode savvy can help.

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


otlaolap
  • Members
  • 43 posts
  • Last active: Sep 12 2013 02:33 AM
  • Joined: 15 Aug 2007
✓  Best Answer

I've found the problem, and it is a typo I made in the original code.  In two or three places I have entered "RunWinTubes" and should have entered "RunWIndTubes".  The compares therefore were in fact compares of a string against a null string, not of the two strings I thought I was comparing.  Glad I said "[b]ut I know I make errors" in the original post.



MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
I get that a lot too. I don't always bother to turn on must declare vars. So every time a make a typo it's a "new" empty variable. happy.png

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski