How can I check that the NSString ends with the certain character(.jpg)?

RAMAN RANA picture RAMAN RANA · Mar 9, 2011 · Viewed 25.9k times · Source

I have a NSString object which is assigned this ("http://vspimages.vsp.virginia.gov/images/024937-02.jpg"). Can anybody tell me how to check whether the string ends with ".jpg"?

Answer

Vladimir picture Vladimir · Mar 9, 2011
if ([[yourString pathExtension] isEqualToString:@"jpg"]){
   //.jpg
}

or

if ([yourString hasSuffix:@".jpg"]){
   //.jpg
}