NSURL file extension addition etc
An alternate approach to the workable solution given on this same page by @user756245 but using different NSString
methods:
NSString *finalString;
if([[tmp pathExtension] isEqualToString:@"xxx"]) {
finalString = [tmp stringByDeletingPathExtension];
}
finalString = [finalString stringByAppendingPathExtension:@"yyy"];
This can be achieved using NSString
's methods. Note that for string comparison, you have to use isEqualToString:
, not ==
, which tests for pointers equality.
About the extension use : -(NSString *)pathExtension;
. To remove the extension use -(NSString *)stringByDeletingPathExtension;
.
In all cases to add an extension, compose a new string using for example : +(NSString *)stringWithFormat:
.
So :
NSString *finalString;
if([[tmp pathExtension] isEqualToString:@"xxx"]) {
finalString = [tmp stringByDeletingPathExtension];
}
finalString = [NSString stringWithFormat:@"%@.yyy", finalString];