关于URL加上特定的的编解码,用到了下面两个接口。
编码:
其实就是把NSString 先用特定的encoding 方式编码,在把他URL 编码。
主要作用就是把一个string编码成特定编码方式的URL可用string。
下面这个函数名字翻译~:string 通过添加%转义符用编码方式:
stringByAddingPercentEsc
apesUsingEncoding:
Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string.
- (NSString *)stringByAddingPercentEsc
apesUsingEncoding
:(NSStringEncoding)encoding
Parameters
encoding
The encoding to use for the returned string.
Return Value
A representation of the receiver using encoding to determine the percent escapes necessary to convert the receiver into a legal URL string. Returns nil if encoding cannot encode a particular character
解码:
对应的解码。
stringByReplacingPercent
EscapesUsingEncoding:
Returns a new string made by replacing in the receiver all percent escapes with the matching characters as determined by a given encoding.
- (NSString *)stringByReplacingPercent
EscapesUsingEncoding:(NSStringEncoding)encoding
Parameters
encoding
The encoding to use for the returned string.
Return Value
A new string made by replacing in the receiver all percent escapes with the matching characters as determined by the given encoding encoding. Returns nil if the transformation is not possible, for example, the percent escapes give a byte sequence not legal in encoding.
注释:PercentEscapes %转义符
===========================================我的使用例子==================================
NSString *st1 = [@"
"
stringByReplacingPercent
EscapesUsingEncoding:NSUTF8StringEncoding
];
NSLog(@"%@",st1);
NSString *st2 = [@"银泰" stringByAddingPercentEsc
apesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@",st2);
输出结果:
之后也在NSURL中测试过,可以使用。
编码:
其实就是把NSString 先用特定的encoding 方式编码,在把他URL 编码。
主要作用就是把一个string编码成特定编码方式的URL可用string。
下面这个函数名字翻译~:string 通过添加%转义符用编码方式:
stringByAddingPercentEsc
Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string.
- (NSString *)stringByAddingPercentEsc
Parameters
encoding
The encoding to use for the returned string.
Return Value
A representation of the receiver using encoding to determine the percent escapes necessary to convert the receiver into a legal URL string. Returns nil if encoding cannot encode a particular character
解码:
对应的解码。
stringByReplacingPercent
Returns a new string made by replacing in the receiver all percent escapes with the matching characters as determined by a given encoding.
- (NSString *)stringByReplacingPercent
Parameters
encoding
The encoding to use for the returned string.
Return Value
A new string made by replacing in the receiver all percent escapes with the matching characters as determined by the given encoding encoding. Returns nil if the transformation is not possible, for example, the percent escapes give a byte sequence not legal in encoding.
注释:PercentEscapes %转义符
===========================================我的使用例子==================================
输出结果:
之后也在NSURL中测试过,可以使用。