Anybody know whats going on here? why is "-" not found? Try it in IRB.
if you do
string = "(( :H – :2B – :3B – :HR )+( 2 * :2B )+( 3 * :3B )+( 4 * :HR ))/ :AB "
string.split(" ")[2] == "-"
it returns false as well.
You're comparing two different dash characters. The normal dash that usually is inputed with the keyboard (ascii character 45) is what you're comparing to, but the text you're parsing has ascii character 8211 (the en dash).
See this http://www.ascii.cl/htmlcodes.htm.
Indeed, if you simply type "-" == "-"
, you'll get true
The character you get from
string.split(" ")[2]
is–
. This may look like a normal hyphen, but it is in fact a different character from the normal hyphen:-
.You can see this by getting the ordinal value of each:
Therefore, you should be checking for equality with the unicode character
\u2013
:Or you can replace all occurrences of
\u2013
with-
: