Confused Confused - 25 days ago 6
iOS Question

String from filename showing %20 where spaces are in the name, unwanted

I'm bringing in images with names that contain spaces, English names and Chinese names, and using those filenames to create strings that are presented beneath their images.

This worked fine until I started putting Chinese into the image file names.

Now, unfortunately all spaces are coming in as

%20


and an example of Chinese looks like this:

%E7%99%BE%E9%A6%99


I have Chinese Simplified installed, and setup in internalisation settings of the project in Xcode... but somehow I'm missing something. Which isn't the first time, and won't be the last.

What do I need to do to make Unicode work?

Answer

The path is urlencoded if you urldecode the path spaces should turn out fine

For Swift 3:

substring.removingPercentEncoding

For Swift 2.3:

substring.stringByRemovingPercentEncoding