Reputation: 319
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.
Upvotes: 0
Views: 113
Reputation: 80273
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
}
}
Upvotes: 2
Reputation: 31722
Use characterAtIndex:
function of NSString
to extract the character by index.
- (unichar)characterAtIndex:(NSUInteger)index
Upvotes: 3
Reputation: 150
if you want to compare a string. Using isEqualToString method.
NSMutableString *str = [[NSMutableString alloc] initWithString:@"a"];
if([str isEqualToString:@"a"]){
// match
}
else{
// not match
}
Upvotes: 0