freepascallazarusutf8-decode

Convert UTF8 to ASCII using lazarus


I am reading some strings from a text file, the problem is that the strings are UTF8 and contain characters that I wish to remove such as: Ă

An not easy solution would be for me to replace each occurence of illegal characters, but because I am lazy I want a simpler solution

So far I tried this :

    line := Utf8ToAnsi(line);

Where line is my UTF8 encoded string ... I tried eaven declaring line as UTF8String ...

Is there a viable solution in this matter? Thanks


Solution

  • An not easy solution would be for me to replace each occurence of illegal characters, but because I am lazy I want a simpler solution

    I developed a function that replaces each diacritical character occurrence to a similar ASCII character, e.g: Á -> A, Ç -> C, ã -> a, and so on. Please take a look at this link.

    HTH