ruby - "-" == "-" returns false.. Why? -


enter image description here

anybody know whats going on here? why "-" not found? try in irb.

if

string = "(( :h – :2b – :3b – :hr )+( 2 * :2b )+( 3 * :3b )+( 4 * :hr ))/ :ab "  string.split(" ")[2] == "-"  

it returns false well.

the character string.split(" ")[2] . may normal hyphen, in fact different character normal hyphen: -.

you can see getting ordinal value of each:

string.split(" ")[2].ord # => 8211 "-".ord # => 45 

therefore, should checking equality unicode character \u2013:

string.split(" ")[2] == "\u2013" # => true 

or can replace occurrences of \u2013 -:

string.gsub!("\u2013", "-") string.split(" ")[2] == "-" # => true 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -