Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

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.
0
philipleighs
Asked:
philipleighs
  • 2
  • 2
1 Solution
 
LischkeCommented:
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
0
 
MadshiCommented:
Yes, Mike is right...  :-)
0
 
philipleighsAuthor Commented:
Thanks Mike. I'll use your idea.
Submit an answer, I'll give you an A.

Cheers, Phil.
0
 
LischkeCommented:
This situation may change in the future when all OSs use Unicode strings by default, because there are defined conversion rules for specific characters. This may take a few years, though.

Ciao, Mike
0
 
philipleighsAuthor Commented:
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;

0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now