I would like to write a string to an NSURL
which may contain characters such as /
or :
, which are not supported by the file system. Is there any convenience method to trim these characters? Or maybe a reference containing all illegal characters, so that I can write such a method myself?
Asked
Active
Viewed 538 times
0

fabian789
- 8,348
- 4
- 45
- 91
1 Answers
2
May be it's better just to escape them with something like this:
NSString *unescaped = @"http://www";
NSString *escapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)unescaped,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);
NSLog(@"escapedString: %@",escapedString);
as it stated here?
Or you can just strip ! * ' ( ) ; : @ & = + $ , / ? % # [ ] characters, if you wish so. Look here for a list of reserved characters.

Community
- 1
- 1

Mark Pervovskiy
- 1,123
- 11
- 18
-
I now replace the `!*'();:@&=+$,/?%#[]` characters. Thanks – fabian789 Oct 30 '12 at 19:27