Text encoding not dealing with accents

I’m playing around with an iOS app that needs to show accented characters (e.g. é).

The app reads the text in from a text file. That works. However, all the accented characters (actually anything not ASCII) comes in as the “unknown character character” at which point we get a runtime exception.

A couple of things:

  1. I put a try-catch around the line that was throwing the exception, and it wasn’t caught.
  2. What am I doing wrong? The amount of text in the file is small (about 10 lines) so I do a readAll on the TextInputStream. I’ve tried setting the encoding. No difference.

At this point I don’t know if it’s me or Xojo (I’m voting me).

If you can share a sample project/sample text file, someone can better help you.

1 Like

Have you set the encoding when you read the text file?

1 Like

Yes: UTF8

Something for the weekend, perhaps.

Do you know the encoding of the text file itself? What encoding does BBEdit report if you open it?

An update:

I have solved (worked around) the problem and possibly found something.

When the accented characters were not working, the file was being copied using a copy script as part of the build. What I did (after an experiment) is place the text in a constant. After doing that, things worked as expected.

That’s because Xojo stores all of its constants as UTF-8. It was about to detect the encoding of the incoming text and properly interpret it. Whatever text editor you used to copy it was also able to figure out what encoding the original file was saved in.

1 Like

Sounds like your text file reading code had a bug in it or was using the wrong encoding.

1 Like