var str = "Hello, playground+"
var allowCharactoers = CharacterSet.urlQueryAllowed
allowCharactoers.remove(Unicode.Scalar("+"))

print(str.addingPercentEncoding(withAllowedCharacters: allowCharactoers))

 

輸出: Optional("Hello,%20playground%2B")

參考資料:

https://stackoverflow.com/questions/31577188/how-to-encode-into-2b-with-nsurlcomponents

arrow
arrow
    全站熱搜

    小賢 發表在 痞客邦 留言(0) 人氣()