在Swift 3中比较字符串会得出错误的结果(Linux) [英] Comparing Strings in Swift 3 gives false results (Linux)
问题描述
我不明白Swift比较字符串的方式.
I don't understand the way Swift compares strings.
在Linux上为Swift(3.0.2):
Swift (3.0.2) on Linux:
print("2" < "=") //returns false
,但其他语言(例如Ruby):
but other languages such as Ruby:
p("2:" < "=:") #returns true
似乎我们应该迅速返回true,因为"2"以ASCII顺序出现在"="之前.是错误还是我错过了什么?
It seems we should have swift returning true since "2" comes before "=" in ASCII order. Is it a bug or do I miss something?
推荐答案
从注释中看,您似乎仅在Linux上对此进行了测试. Swift在Linux上如何处理字符排序方面存在一个未解决的错误,请参见 SR-530
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
原始答案:
Ruby的p
返回作为其参数传递的对象.
Ruby's p
returns object passed as its argument.
等效比较将是Ruby puts
与Swift print
.两者都(几乎)不返回任何内容.
Equivalent comparison would be Ruby puts
vs Swift print
. Both return (almost) nothing.
这篇关于在Swift 3中比较字符串会得出错误的结果(Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!