1.NSString 方法
stringByAddingPercentEncodingWithAllowedCharacters? 需要傳一個(gè)??NSCharacterSet? 對(duì)象
如[NSCharacterSet ?URLQueryAllowedCharacterSet]
URLFragmentAllowedCharacterSet "#%<>[\]^`{|}
URLHostAllowedCharacterSet? ? ? "#%/<>?@\^`{|}
URLPasswordAllowedCharacterSet? "#%/:<>?@[\]^`{|}
URLPathAllowedCharacterSet? ? ? "#%;<>?[\]^`{|}
URLQueryAllowedCharacterSet? ? "#%<>[\]^`{|}
URLUserAllowedCharacterSet? ? ? "#%/:<>?@[\]^`
2. ?
let customAllowedSet = NSCharacterSet(charactersInString:"`#%^{}\"[]|\\<> ").invertedSet
NSString *urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]];