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.
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.
Yes, Mike is right... :-)
ASKER
Thanks Mike. I'll use your idea.
Submit an answer, I'll give you an A.
Cheers, Phil.
Submit an answer, I'll give you an A.
Cheers, Phil.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again Mike,
Here is the routine for those interested:
const
AccentedChars = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×Ø ÙÚÛÜÝÞßàáâ ãäåæçèéêëì íîïðñòóôõö ÷øùúûüýþÿ' ;
BaseChars = 'AAAAAAACEEEEIIIIDNOOOOOxO UUUUY__aaa aaaaceeeei iiionooooo _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;
Here is the routine for those interested:
const
AccentedChars = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×Ø
BaseChars = 'AAAAAAACEEEEIIIIDNOOOOOxO
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;
{ describes equivalent chars }
EquivChars: array[1..2] of ShortString = (
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜ
'AAAAAACEEEEIIIINOOOOOUUUU
);
Ciao, Mike