to know the character in a object-c nsstring object
I have an NSString *str and I want to know if the 2nd character 开发者_StackOverflowis equal to a. How can I do this? I'm new to objective c.
Use this:
[str characterAtIndex:1]
But I always encourage you to check documentation first!
You could also use:
[[str substringWithRange:NSMakeRange(1,1)] isEqualToString:@"a"];
Admittedly, this only becomes handy when you have longer strings for which you're searching.
精彩评论