Comparing Strings in Swift 3 gives false results (Linux)

随声附和 提交于 2019-12-13 08:07:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!