What exactly does rangeOfCharacterFromSet do?
10,281
See the documentation for that method, and for the more general method it's implemented with.
Author by
farhadf
Updated on June 04, 2022Comments
-
farhadf almost 2 years
NSString *foo = @" x "; NSRange r = [foo rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; NSLog(@"foo range = %d,%d",r.location, r.length);
Results in "foo range = 0,1"
So will it ever return a length > 1?
-
Rob Napier over 14 yearsIt may be helpful here to note that the reader should consult rangeOfCharacterFromSet:options:range: to understand the full details and why length can be greater than 1. The linked function implies you need to keep reading (and then keep reading again since the reference method points to to yet another), but may be confusing to those unfamiliar with Apple's doc style.
-
farhadf over 14 yearsThanks - I had actually read the documentation for the function I was using, and had not continued to read, so I didn't see the "discussion" note in rangeOfCharacterFromSet:options:range:.
-
Nico about 13 years@Rob Napier: Thanks again; while updating the link just now, I took the opportunity to add a link to the more specific method (with the actual explanation, as you note) to make it clearer.