NSString question - rangeOfString method

≯℡__Kan透↙ 提交于 2019-11-28 21:07:57
Jared Pochtar

From the documentation of NSString

-[NSString rangeOfString]

Return Value

An NSRange structure giving the location and length in the receiver of the first occurrence of aString. Returns {NSNotFound, 0} if aString is not found or is empty (@"").

So it looks like:

if ([@"abc" rangeOfString:@"d"].location == NSNotFound){
  //Do something

Is the Apple-approved way.

EDIT:

I made a really bad typo, fixed it, thanks Kalle.

Check the length of the range. If it's non-zero, it was found.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!