Solved

Converting strings

Posted on 1999-01-22
5
219 Views
Last Modified: 2010-08-05
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
Comment
Question by:philipleighs
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 1362770
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1362771
Yes, Mike is right...  :-)
0
 
LVL 3

Author Comment

by:philipleighs
ID: 1362772
Thanks Mike. I'll use your idea.
Submit an answer, I'll give you an A.

Cheers, Phil.
0
 
LVL 10

Accepted Solution

by:
Lischke earned 20 total points
ID: 1362773
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
 
LVL 3

Author Comment

by:philipleighs
ID: 1362774
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question