#pragma mark *** string comparison and equality ***
//這是字串用來比較的方法 */
- (nscomparisonresult
)compare:(
nsstring
*)string;
- (nscomparisonresult
)compare:(
nsstring
*)string options:(
nsstringcompareoptions
)mask;
- (nscomparisonresult
)compare:(
nsstring
*)string options:(
nsstringcompareoptions
)mask range:(
nsrange
)comparerange;
- (nscomparisonresult
)compare:(
nsstring
*)string options:(
nsstringcompareoptions
)mask range:(
nsrange
)comparerange locale:(
nullable
id)locale;
// locale arg used to be a dictionary pre-leopard. we now accept nslocale. assumes the current locale if non-nil and non-nslocale. nil continues to mean canonical compare, which doesn't depend on user's locale choice.
- (nscomparisonresult
)caseinsensitivecompare:(
nsstring
*)string;//忽略大小寫進行字串比較
- (nscomparisonresult
)localizedcompare:(
nsstring
*)string;//本地化比較
- (nscomparisonresult
)localizedcaseinsensitivecompare:(
nsstring
*)string;//本地化比較並且不區分大小寫
- (nscomparisonresult
)localizedstandardcompare:(
nsstring
*)string;//
它對應的選項是 nscaseinsensitivesearch 、 nsnumericsearch 、nswidthinsensitivesearch 以及 nsforcedorderingsearch 。如果我們要在ui上顯示乙個檔案列表,用它就最合適不過了。
返回值nscomparisonresult是乙個結構體型別
typedef
ns_enum
(nsinteger, nscomparisonresult) ;
nsorderedascending公升序,代表左邊的值比右邊的小;
nsorderedsame左右兩個值大小相同;
nsordereddescending降序,代表左邊的值比右邊的大。
比較方法:根據輸入的options值決定比較順序,依次比較各個字元的值的大小(a-z依次遞增),第乙個不一樣的值決定比較結果大小
引數型別nsstringcompareoptions是乙個結構體型別
typedef
ns_options
(nsuinteger, nsstringcompareoptions) ;
location
: 需要比較的字串起始位置(以0為起始)
NSString 的比較用法
今天要做通訊錄搜尋功能,所以就把比較文件看了下 nsstring value 1234567890 比較的方法 value compare nsstring value compare nsstring options nsstringcompareoptions value compare nss...
NSString比較詳解
nsstring value 1234567890 比較的方法 value compare nsstring value compare nsstring options nsstringcompareoptions value compare nsstring options nsstringco...
NSString 初始化方法的記憶體比較
nsstring str1 hello nsstring str2 hello nsstring str3 nsstring stringwithformat hello nsstring str4 nsstring stringwithstring hello nsstring str5 nsst...