How to append a string in another string in objective c iphone

cocoa-touch, ios, objective-c

Solution

The most complete and general way, but not the simplest, is something like this:

NSString *filename = @"DSC004.jpg";
NSString *ext = [filename pathExtension];
NSString *basename = [filename stringByDeletingPathExtension];
NSString *updated = [basename stringByAppendingString:@"-Add"];
NSString *finalName = [updated stringByAppendingPathExtension:ext];

This approach works with full pathnames or filenames and files with multiple periods in the name,.

Problem

I am working with array of images containing images with jpg,png and gif extensions.I need to append a string @"-Add" to every image in array just before the extension.How can i achieve this. For ex :i have a image DSC004.jpg and i want to append string "-Add" ,so that my image name becomes DSC004-Add.jpg.????? I thought of deleting the extension ,appending the required string and then again appending the extension.But my array of images has different extension with every image name.PLs help me out

Original source