Encode URL StringByAddingPercentEscapes

https://stackoverflow.com/questions/24551816/swift-encode-url


NSString* encodedString = (NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)unencodedString,NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 );


let originalString = "test/test"

let escapedString = originalString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)

print(escapedString!)

你可能感兴趣的:(Encode URL StringByAddingPercentEscapes)