Solved

Converting strings

Posted on 1999-01-22
5
218 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 191
Process Javascript errors with Delphi TWebBrowser 1 113
Convert a string into a TDateTime 5 50
tidtcpserver connection lost handle 2 71
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now