开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜