I have a C# code that reads a text file (.txt) file via TextAsset and I’m having trouble to maintain special characters. The word Leão (lion in portuguese) turns to Leo, for example.
Here’s the basic code:
public TextAsset references; //here I load the txt file, something like a csv
string[] valores;
valores = references.text.Split(' ; ');
All code are working fine. The problem is just these especial characters. Heres some other examples:
Búfalo = Bfalo
Cão = Co
etc…
Any tips? I’ve already tried saving the scripts in UTF-8…
Fixed that! I’d to save 2 scripts that uses parts of the text asset in UTF-16 and open the asset in MonoDevelop (mac) to fix the words with special chars!
Just hit this issue myself, and I’ve found a reasonable fix. Normally, TextAssets will strip non-ASCII characters (as specified here), unless you save your asset with a .bytes extension.
So, you can change/copy your TextAsset file to have a .bytes extension (e.g. blah.txt becomes blah.bytes). Then, if you import the byte array and convert back to a string with the correct encoding, special characters appear just fine.
// You might also get this file from an AssetDatabase or elsewhere.
TextAsset byteAsset = Resources.Load<TextAsset>("resources/path/to/my/bytes/file");
// There are other options for Encoding.*.GetString, in case Default fails.
string contents = System.Text.Encoding.Default.GetString(byteAsset.bytes);
Note that this avoids using System.IO file operations, which don’t play nicely with builds since Resources won’t be accessible through normal file I/O.
(I’m still using Unity 5.5.4 so it’s possible that there’s some newer solution.)
Actually it is 11 years later. Please don’t necro-post. Start a new thread as per forum rules.
Make your thread meaningful. For instance, since you can see the characters (those goofy inverse tick marks), do a check YOURSELF and say “I checked my font and it is capable of displaying these characters,” because then we know you actually are bringing something to the table.
So please, start your own fresh post, and when you post, post complete troubleshooting steps. Here’s how:
How to report your problem productively in the Unity3D forums:
This is the bare minimum of information to report:
what you want
what you tried
what you expected to happen
what actually happened, log output, variable values, and especially any errors you see
links to documentation you used to cross-check your work (CRITICAL!!!)
The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?