[英]Trim any illegal characters from NSURL before writing to disk
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. 我想写一个字符串到一个
NSURL
,它可能包含文件系统不支持的字符,如/
或:
。 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?
或者也许是包含所有非法字符的引用,以便我自己可以编写这样的方法?
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 .
在这里查看保留字符列表 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.