开发者

How to comapare the string character by character in Objective c?

Iam developing one applciation.In that i want to开发者_运维百科 comapare the every character of string with other character.So please tell me how to do that one.


Use characterAtIndex: function of NSString to extract the character by index.

- (unichar)characterAtIndex:(NSUInteger)index


for (int i=0; i<[string length]; i++) {
   char = [string characterAtIndex:i];
   NSString *charString = [NSString stringWithFormat:@"%c", char];
   if ([charString isEqualToString:comparisonString]) {
      //match
   }
   else {
      //no match
   }
}


if you want to compare a string. Using isEqualToString method.

NSMutableString *str = [[NSMutableString alloc] initWithString:@"a"];
if([str isEqualToString:@"a"]){
  // match
}
else{
  // not match
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜