I have some code in a function that does a simple string comparison.
If stringa = stringb then …
What’s puzzling me is that when I run on Windows the function finds the match, but on Mac it doesn’t. When stepping through the program the strings look identical. Could it be that the Mac adds some kind of invisible end of line type character to the string?
Checking the binary values of both strings they are identical. They should be identical. To windows, they are identical. To Mac, they aren’t.
I decided to make the check work with a different kind of loop, and then suddenly it worked. I’ll post the two variants below. Does anyone have any idea why one would work and the other not? In my mind, they are identical. The only difference between the code below and the code in my project is that the strings are memebers of a class.
Works on Mac and Windows:
[code] Remove(input as string)
dim i as integer
for each s as string in aStrings
if s = input then
try
// then remove it
aStrings.remove(i)
return true
catch
// there was some kind of problem
setLastError "unable to remove string"
return false
end try
end if
i = i + 1
next
// return false to show that we were unsuccessful
setLastError “unable to find string”
return false[/code]
Code that works on Windows but doesn’t work on Mac:
[code] dim i as integer
dim size as integer = UBound(aStrings)
while i < size
// if the string matches the string in the array
if aStrings(i) = input then
try
// then remove it
aHotkeys.remove(i)
return true
catch
// there was some kind of problem
setLastError “unable to remove string”
return false
end try
end if
i = i + 1
wend
// return false to show that we were unsuccessful
setLastError “unable to find string”
return false[/code]
I haven’t tried the code in a fresh new project. But if it works in a new project, my next question would be: why? Maybe this is some kind of complex bug. I don’t know.