我有一个赋予它的NSString对象(“http://vspimages.vsp.virginia.gov/images/024937-02.jpg”)。任何人都可以告诉我如何检查字符串是否以“.jpg”结尾?
答案 0 :(得分:133)
if ([[yourString pathExtension] isEqualToString:@"jpg"]){
//.jpg
}
或
if ([yourString hasSuffix:@".jpg"]){
//.jpg
}
答案 1 :(得分:6)
if( [[yourString pathExtension] caseInsensitiveCompare:@"jpg"] == NSOrderedSame ) {
// strings are equal but may not be same case
}
答案 2 :(得分:2)
NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.png' AND self BEGINSWITH[c] %@",@"img_"];
if([fltr evaluateWithObject:strPath])
{
// string matched....
}