I have programmed for years, but am new to xcode and objective c. I just wanted to double check my code and see if there were any problems with memory or suggestions for better ways to handle stuff. I have searched in books and online, but most places just set a string and don't do any editing/parsing.
This is a function to take a windows folder path (entered by a user), and clean it up before saving it to a database. Please let me know if this is properly done or not. Thanks for any feedback!
This is a function to take a windows folder path (entered by a user), and clean it up before saving it to a database. Please let me know if this is properly done or not. Thanks for any feedback!
Code:
- (NSString *)getCleanUNCPath {
NSMutableString *transPath = [NSMutableString stringWithString:[self.allSettings objectForKey:@"FTPTranslatedPath"]];
//Make sure all slashes are correct
[transPath replaceOccurrencesOfString:@"/" withString:@"\\" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [transPath length])];
//Strip leading and ending slashes (we will replace in case the have too many/not enough)
while ([transPath characterAtIndex:0] == '\\') {
[transPath deleteCharactersInRange:NSMakeRange(0, 1)];
}
while ([transPath characterAtIndex:([transPath length] - 1)] == '\\') {
[transPath deleteCharactersInRange:NSMakeRange(([transPath length] - 1), 1)];
}
//Add the leading double slash
transPath = [NSMutableString stringWithFormat:@"\\\\%@", transPath];
//Add the ending slash
[transPath appendString:@"\\"];
return transPath;
}