简体   繁体   中英

check for garbage value Objective c

I am trying to get the range of a particular substring using rangeOfString method of the NSString instance.. the problem is it sometimes returns garbage value..

Is there a way i could do a comparison for the garbage value and skip the next steps if the range sent is garbage..

thanks!

If the range is not found, you'll get a NSRange with {NSNotFound, 0} . You can find this here in the documentation.

This is the test you'll want:

NSRange range = [myString rangeOfString:@"doobleydoo"];
if (range.location == NSNotFound) return;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM