0

I am using swift language 2.1.1

I am applying encoding mechanism on the string value. I used the following code,

let text = "-/:;.,?!'()&@*+=_~"

let encodedText = text!.stringByAddingPercentEscapesUsingEncoding(NSUTF16StringEncoding)

In my case, none of the characters are encoded.

May I have the solution on this

2 Answers2

0

Try this...

let encodedText = text.stringByAddingPercentEncodingWithAllowedCharacters( NSCharacterSet.URLQueryAllowedCharacterSet())
Bhoomi Jagani
  • 2,413
  • 18
  • 24
0

Maybe this is what you want

let encodedText = text.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.alphanumericCharacterSet())
ielyamani
  • 17,807
  • 10
  • 55
  • 90