- Home /
Storing special symbols in string (š, č, á, é, etc.).
Hello, I am creating a strategy game where I store cities in a text asset and every value they have is stored there as well as their name. Getting that name out is no problem but the problem comes when I have a city with special symbol - I'm Czech so I'm testing some Czech names and all the special symbols are unknown for the string. The problem is not in font, because whenever I start the game and then in editor change the value to the one with a special symbol, the game is able to show it to me properly - in other words, the font knows these symbols. So my question is - how can I store special characters in a string variable so I can properly show the name of the city when the player clicks on it?
Answer by VadimMinsk · Mar 02, 2020 at 02:19 PM
Your asset is encoded with ANSI, and ANSI doesn't support special symbols. You need to save the file with encoding different than ANSI, like for example Unicode
I should also add that I am an absolute walnut! I created my text file in notepad with UTF-8 encoding but then I wanted to edit the file and wanted to do that in many rows at once. When I did that, I wrote all the names in visual studio (unity opened that in visual studio) which don't encode that in UTF-8 - hence the source of my own problems.
Answer by Zentiu · Mar 02, 2020 at 12:57 PM
Hiya.
Try putting the special symbols in a char array and pull them out whenever you need it for each name.
public Char[] specialSymbols = {é, á, ê, û};
public string cityName;
public Start ()
{
cityName = "foo" + char[2].ToString() + "bar";
}
You can put the char array in a static class so you can pull it out from anywhere saving you the hassle of copy pasting the array over and over.
Your answer
Follow this Question
Related Questions
Automatically resize scrollview based on vertical text length (Solved) 2 Answers
C# Check spelling of a word. 1 Answer
Parsing a Custom Scripting Language 0 Answers
os specific paths in strings? 1 Answer
String format not working 1 Answer