OC判断字符串是否以某个字符串开头或结尾或包含
2018-06-15 本文已影响20人
有生之年丶U
生活有度,人生添寿。 —— 书摘
NSString *imagePath = @"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1333967633,2116729047&fm=27&gp=0.jpg";
// 判断是否是“https://”开头
[imagePath hasPrefix:@"https://"];
// 判断是否是“.jpg”结尾
[imagePath hasSuffix:@".jpg"];
// 判断是否包含“bdstatic”
if([imagePath rangeOfString:@"bdstatic"].location==NSNotFound) {
NSLog(@"不包含bdstatic");
} else {
NSLog(@"包含bdstatic");
}