开发者

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

开发者 https://www.devze.com 2023-03-30 19:48 出处:网络
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 NSStr

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

精彩评论

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