I would like to check if my NSString end with @2x.png (case insensitive). How can I do that?
I have this code now, but it seems to ignore the @2x part.
NSString *fileName = [_sourcePath lastPathComponent];
[fileName stringByReplacingOccurrencesOfString:@"@2x" withString:@""];
[fileName stringByReplacingOccurrencesOfString:@"@2X" withString:@""];
NSLog(@"Filename: %@", fileName);
2012-01-01 21:00:55.600 NewApp[23930:707] Filename: myfile@2x.png
You need to re-assign your variable because NSString is immutable (state cannot be modifieid). Try:
Alternatively, if you want to do the replacements inline use a
NSMutableStringandreplaceOccurrencesOfString:withString:options:rangewhich will do the replacement inline.