Find the location of a specific character in NSString

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

I tried this, but it returns an empty range (I want to find the location "?"):

NSRange range = [@"This is a ? test to see if it works" rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"?"]];
+3
source share
2 answers

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

+1
source
Maybe this will work?
NSString* s = @"hello?";
NSRange range = [s rangeOfString:@"?"];
+3
source

Source: https://habr.com/ru/post/1756200/


All Articles