var str1 = "hello"
var str2 = "Hello"
if str1 < str2 { print("hello is less than Hello")}
else {print("hello is more than Hello")}
str1がstr2のより大きいことが判明しているものに基づい?
var str1 = "hello"
var str2 = "Hello"
if str1 < str2 { print("hello is less than Hello")}
else {print("hello is more than Hello")}
str1がstr2のより大きいことが判明しているものに基づい?
2つの文字列は、各文字のUnicode値を使用して文字ごとに比較されます。 h
はH
(U + 0048)よりも高いコード(U + 0068)を持つので、str1
はstr2
より大きい。
質問の下にあるマーティンのコメントに基づいて、それは私が述べたよりも少し複雑です。詳細はWhat does it mean that string and character comparisons in Swift are not locale-sensitive?をご覧ください。
私はそれがレキシカルオーダーに基づいていると思います。 https://en.wikipedia.org/wiki/Lexicographical_order
スイフト列が Unicode Collation Algorithmに従って比較され、 これらの「分解」の文字列の(有効)、
、"hello
」と"Hello"
は、Unicodeが
hello: U+0068, U+0065, U+006C, U+006C, U+006F
Hello: U+0048, U+0065, U+006C, U+006C, U+006F
ので、"Hello" < "hello"
値を有する。
"正常化" または "" 分解発音区別符号付き文字 に関連する例であります例として、
a = U+0061
ä = U+00E4
b = U+0062
は、分解された形態を有する。
a: U+0061
ä: U+0061, U+0308 // LATIN SMALL LETTER A + COMBINING DIAERESIS
b: U+0062
したがって"a" < "ä" < "b"
。詳細および例については
、What does it mean that string and character comparisons in Swift are not locale-sensitive?
関連を参照してください:[それはスウィフトでその文字列と文字比較は、ロケールに依存していない何を意味するのでしょうか?](http://stackoverflow.com/questions/25713975/what文字列と文字の比較を迅速に行うことができます。 –