現在、ユーザーがテキストを入力して「 Enter 」をタップすると、リクエストが送信される HTTP POST リクエストに追加される文字列を設定しようとしています。
次のように、複数の文字 (^、+、<、>) を単一の文字 ('_') に置き換えることができることを知っています。
userText.replacingOccurrences(of: "[^+<>]", with: "_"
現在、次の複数の機能を使用しています。
.replacingOccurrences(of: StringProtocol, with:StringProtocol)
そのようです:
let addAddress = userText.replacingOccurrences(of: " ", with: "_").replacingOccurrences(of: ".", with: "%2E").replacingOccurrences(of: "-", with: "%2D").replacingOccurrences(of: "(", with: "%28").replacingOccurrences(of: ")", with: "%29").replacingOccurrences(of: ",", with: "%2C").replacingOccurrences(of: "&", with: "%26")
これを行うより効率的な方法はありますか?