- (nullableNSString*)stringByAddingPercentEncodingWithAllowedCharacters:(NSCharacterSet*)allowedCharactersAPI_AVAILABLE(macos(10.9), ios(7.0), watchos(2.0), tvos(9.0));
summary:
Returns a new string made from the receiver by replacing all characters not in the specified set with percent-encoded characters.
用编码后的百分号字符, 取代所有不在特定集合的字符;
discussion:
Entire URL strings cannot be percent-encoded, because each URL component specifies a different set of allowed characters. For example, the query component of a URL allows the “@” character, but that character must be percent-encoded in the password component.UTF-8 encoding is used to determine the correct percent-encoded characters. Any characters in allowedCharacters outside of the 7-bit ASCII range are ignored.
allowedCharacters代表需要编码的字符,在集合中的话就需要编码。例如结合中包含“|”,编码后就会变成"%7C";
网友评论