开发者

to know the character in a object-c nsstring object

开发者 https://www.devze.com 2023-03-14 08:54 出处:网络
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:

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

精彩评论

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