Created
December 4, 2014 22:05
-
-
Save Air-Craft/4eab9f089c1c9628e57f to your computer and use it in GitHub Desktop.
Sanitise string filtering out bad characters #strings #intermediate #objective-c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Native... | |
| NSCharacterSet* illegalFileNameCharacters = [NSCharacterSet characterSetWithCharactersInString:@"/\\?%*|\"<>"]; | |
| NSString *sanitized = [[fileName componentsSeparatedByCharactersInSet:illegalFileNameCharacters] componentsJoinedByString:@""]; | |
| // With Overline (negative matching) | |
| NSString *sanitized = [fileName stringByReplacingOccurrencesOfRegExpPattern:@"[^a-zA-Z0-9_\\+\\-]+" withString:@"_" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment