Solved

Converting strings

Posted on 1999-01-22
5
215 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
Comment Utility
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
Comment Utility
Yes, Mike is right...  :-)
0
 
LVL 3

Author Comment

by:philipleighs
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

9 Experts available now in Live!

Get 1:1 Help Now