Link to home
Start Free TrialLog in
Avatar of philipleighs
philipleighs

asked on

Converting strings

Hi team,

Does anyone know how to convert a string like
'äbçdé'
to
'abcde'?

I thought OemToChar would do it. Some code like this prehaps:

var Res: string;
begin
    Res := '';
    SetLength(Res, 50);
    OemToChar('äbçdé', PChar(Res));
    ShowMessage(Res);

But ShowMessage displays 'SbtdT' instead of 'abcde' on Win95!
Anyone know how to make it work?

Thanks,
Phil.
Avatar of Lischke
Lischke

There's no easy way to convert those characters as you want. There's no simple correlation between ä and a as between A and a etc. You need to define a conversion table and code the conversion yourself. I use a table like:

{ describes equivalent chars }
EquivChars: array[1..2] of ShortString = (
     'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝß¿¡'+'´`’‘',
     'AAAAAACEEEEIIIINOOOOOUUUUYS?!'+#39#39#39#39
   );

Ciao, Mike
Yes, Mike is right...  :-)
Avatar of philipleighs

ASKER

Thanks Mike. I'll use your idea.
Submit an answer, I'll give you an A.

Cheers, Phil.
ASKER CERTIFIED SOLUTION
Avatar of Lischke
Lischke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again Mike,

Here is the routine for those interested:

const
  AccentedChars = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ';
  BaseChars =     'AAAAAAACEEEEIIIIDNOOOOOxOUUUUY__aaaaaaaceeeeiiiionooooo_ouuuuy_y';
function RemoveAccents(s: string): string;
  var Count: Integer;
      AccentCharPos: Integer;
  begin
    Result := s;
    for Count := 1 to Length(Result) do
      begin
        AccentCharPos := Pos(s[Count], AccentedChars);
        if AccentCharPos <> 0 then
          Result[Count] := BaseChars[AccentCharPos];
      end;
  end;