判断NSString中是否包含另一个字符串

2017-06-22  本文已影响444人  FallPine

判断字符串中是否包含另一个字符串有一下方法

// 字符串是否包含有某字符串
NSString *title = @"How are you?";
[title containsString:@"are"]
yes : 包含are字符串; no : 不包含 

[title rangeOfString:@"are"].location == NSNotFound
yes(即等于NSNotFound) : 不包含; no : 包含 



// 字符串开始包含有某字符串
[title hasPrefix:@"are"]
yes : 包含; no : 不包含 

//字符串末尾有某字符串
[string hasSuffix:@"bitch"]
yes : 包含; no : 不包含

参考文章:【艾姆希 】【iOS开发—判断NSString是否包含某个字符串】

上一篇下一篇

猜你喜欢

热点阅读