开发者

What is purpose of using NSOrderedSame? [duplicate]

This question already has an answer here: 开发者_开发问答 Closed 11 years ago.

Possible Duplicate:

Is there a difference between NSString compare: and isEqual(ToString):?

What is the purpose of using NSOrderedSame in the below line of code?

if([result caseInsensitiveCompare:@"ERROR"]==NSOrderedSame)

where result is a string variable.


The compare methods in Cocoa and Cocoa Touch return how the compared objects should be ordered, instead of just returning a boolean that tells whether the values are the same or not. There are three values:

  • NSOrderedAscending: The left operand is smaller than the right operand.
  • NSOrderedSame: The two operands are equal.
  • NSOrderedDescending: The left operand is greater than the right operand.

So your code simply checks whether the string pointed to by result is equal to the string "ERROR", ignoring differences in case (that is, "error", "eRRoR" etc. are all considered to be equal to "ERROR").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜