0

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Confused
  • 6,048
  • 6
  • 34
  • 75
  • With strings like Chinese names, in console usually its represented by unicode characters but properly shown in UI. Please go through below question it may be good place to start http://stackoverflow.com/questions/31272561/working-with-unicode-code-points-in-swift – Dileep Nov 15 '16 at 18:22
  • @DILi These are not showing correctly in the app, either. It's not just the console that's a problem, it's an issue with the file name encoding, as per Misha's answer. This isn't strings in a text file or copy-pasted into the app, it's the actual file names of imported image files. As a result, the file names, when grabbed inside the app seem to be coming in encoded with percent encoding. Whatever that is. – Confused Nov 15 '16 at 18:27

1 Answers1

3

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
Eric Aya
  • 69,473
  • 35
  • 181
  • 253