开发者

Find location of specific character in NSString

开发者 https://www.devze.com 2023-01-08 19:39 出处:网络
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 \'?\'):

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

精彩评论

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