My string has & and I want to replace it with the percentage encoding (%26). This is just an example. There can be any escape character.
I tried this but it is not replacing & with %26 :
password.text?.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)