views:

43

answers:

2

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 characterSetWithCharactersInString:@"?"]];
A: 

maybe this will work?

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

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

V1ru8
Debugger shows 0,0 but the if statement checking this fails... hmmmm...Thanks anyway for confirming.
Egil