问题
I don't understand the way Swift compares strings.
Swift (3.0.2) on Linux:
print("2" < "=") //returns false
but other languages such as Ruby:
p("2:" < "=:") #returns true
It seems we should have swift returning true since "2" comes before "=" in ASCII order. Is it a bug or do I miss something?
回答1:
From the comments, it seems that you are testing this on Linux only. There is an open bug how Swift handles char ordering on Linux, see SR-530
Original answer:
Ruby's p
returns object passed as its argument.
Equivalent comparison would be Ruby puts
vs Swift print
. Both return (almost) nothing.
来源:https://stackoverflow.com/questions/42317699/comparing-strings-in-swift-3-gives-false-results-linux