I\'m using very tricky fighting methods :) to make a string like Fi?le*/ Name
safe for using as a file name like File_Name
.
I\'m sure there is a cocoa
According to wikipedia, the most common characters that should be excluded from filenames are:
/\?%*|"<>
http://en.wikipedia.org/wiki/Filename
Given that, and since the invertedSet operation in the alternate solution can be intensive, to me the below is a cleaner approach:
NSCharacterSet *invalidFsChars = [NSCharacterSet characterSetWithCharactersInString:@"/\\?%*|\"<>"];
NSString *scrubbed = [originalStr stringByTrimmingCharactersInSet:invalidFsChars];
This way you can still allow filenames that have dash, etc.