Convert Hi-Ansi chars to Ascii equivalent (é -> e)

前端 未结 4 1877
南旧
南旧 2020-12-04 22:14

Is there a routine available in Delphi 2007 to convert the characters in the high range of the ANSI table (>127) to their equivalent ones in pure ASCII (<=127) according

4条回答
  •  甜味超标
    2020-12-04 22:39

    Just to extend Craig's answer for Delphi 2009:

    If you use Delphi 2009 and newer, you can use a more readable code with the same result:

    function OStripAccents(const aStr: String): String;
    type
      USASCIIString = type AnsiString(20127);//20127 = us ascii
    begin
      Result := String(USASCIIString(aStr));
    end;
    

    Unfortunately, this code does work only on MS Windows. On Mac, the accents are not replaced by best-fitted characters but by question marks.

    Obviously, Delphi internally uses WideCharToMultiByte on Windows whereas on Mac iconv is used (see LocaleCharsFromUnicode in System.pas). The question is if this different behaviour on different OS should be considered as bug and reported to CodeCentral.

提交回复
热议问题