开发者

Find location of specific character in NSString

How can I find the location of a specific character in an NSString?

I have tried this but it returns an empty range (I want to find the location of the '?'):

NSRange range = [@"This is a ? test to see if it works" rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInStrin开发者_如何学运维g:@"?"]];


maybe this will work?

NSString* s = @"hello?";
NSRange range = [s rangeOfString:@"?"];


You must doing something else wrong. Because this is absolutely correct and returns {10, 1}. At least on my mac it does ;-)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜