Problem with special characters in Strings (like ä, ü, ß, €)

Hi,

I wanted to edit this library so that it can also display special characters (like ä, ö, ß, €) on my tft display.
My problem is that the library uses an 1 byte-identifier for charachter drawing (ASCII).
So i thought i could implement the ISO 8859-15 standard in only one byte as it has all the characters I need.
Arduino can display these special characters as it uses UTF-8.
In UTF-8 some characters are represented with more than one byte ( € is 0x E8 82 AC).

So I wrote a simple convert function that tries to solve the problem mentioned above:

String convertAscii(String input)
{
  String ret = "";
  Serial.println(input);
  Serial.println("Length: " + String(input.length()));
  for (int i = 0; i < input.length(); i ++)
  {
    char c = input.charAt(i);
    //ret = ????
    Serial.println(String(c) + " , " + String(isAscii(c)) + ", " + String((c), HEX));
  }
  return ret;
}

When I call the function with e.g. "€" I get this output:

€
Length: 3
⸮ , 0, e2
⸮ , 0, 82
⸮ , 0, ac

So stuff with char and String.length() doesn't work on those strings.
Now I have no clue what I should do about it.
Could You please help me?

Wow. You are way off in the weeds.

Instead of trying to include the special characters in your source code just use the ISO 8859-15 byte value...

#define SYMBOL_EURO  "\xA4"

Serial.println( SYMBOL_EURO "42" );

The problem is that I have a given string ( from an external source) where I can't change the formatting like in your post.

Edit: I tried Your code but my result is ⸮42

In which case you have excluded critical information.

So after a bit of thinking I updated the function:

String convertAscii(String input)
{
  bool nextReadChar = false;
  String ret = "";
  Serial.println("Input: " + input);
  Serial.println("Length: " + String(input.length()));
  for (int i = 0; i < input.length(); i ++)
  {
    char c = input.charAt(i);
    Serial.println(c, HEX);
    if (nextReadChar)
    {
      nextReadChar = false;
      ret += c;
    }
    else
    {
      if (c < 127)
      {
        ret += c;
      }
      else
      {
        if (c == 0xC3) //latin-9 table
        {;
          nextReadChar = true;
        }
        else if (c == 0xE2) //€
        {
          nextReadChar = true;
          i++;
        }
      }
    }
  }
  return ret;
}

Now my problem is solved. Note that it uses UTF-8 as standard as it's apperantly a little bit different to the special char ASCII

        {;

I don't think I've seen THAT done before.

PaulS:

        {;

I don't think I've seen THAT done before.

Compiler will optimize that out. But yes, that is a first.