iOS 字符编码

2019-03-29  本文已影响0人  JopYin

iOS 9之后苹果推荐使用编码方法

[str  stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]

//    URLFragmentAllowedCharacterSet    "#%<>^`\[]{|}
//    URLPasswordAllowedCharacterSet    "#%<>^`\[]{|}/:?@
//    URLPathAllowedCharacterSet        "#%<>^`\[]{|};?
//    URLQueryAllowedCharacterSet       "#%<>^`\[]{|}
//    URLUserAllowedCharacterSet        "#%<>^`\[]/:?@
//    URLHostAllowedCharacterSet        "#%<>^`\{|}/?@
NSString *string = @"$&1111😆aaaaa#";
NSString *unicode = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
屏幕快照 2019-03-29 16.25.53.png

打印结果:$&1111%F0%9F%98%86aaaaa%23
由此可以看出表情😆 和 # 是进行编码 的其他字符是不进行编码。

上一篇 下一篇

猜你喜欢

热点阅读