I am currently trying to setup a string to be added to a HTTP POST request where a user would type text and tap 'enter' and a request would be sent.
I know multiple characters (^,+,<,>) can be replaced with a single character ('_') like so:
userText.replacingOccurrences(of: "[^+<>]", with: "_"
I currently am using multiple functions of:
.replacingOccurrences(of: StringProtocol, with:StringProtocol)
like so:
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")
Is there a more efficient way of doing this?