Need a routin to convert a utf-8 file to EBCDIC (in Delphi 2007)

Can someone help me with a routine to convert a utf-8 file to EBCDIC (in Delphi 2007)
LVL 1
puckoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

louislietaerCommented:
declare an array of char [1..256] for ebcdic
init array with the value in http://www.legacyj.com/cobol/ebcdic.html
translate ut8 to ascii (you will find this in the delphi library)

then write something like :

myEbcdicSt:=''; // asciistring
for i := 1 to length(myasciistr) do
begin
  myEbcdicStr:=myEbcdicStr+EbcdicArr[asc(myasciistr[i])];
End;
0
puckoAuthor Commented:
Yeah that's for ascii

Already done that like the code below but I need to go from a utf-8 file here and be able to handle more chars than the 256 ascii characters. (for example swedish charaters etc)
rocedure TForm10.Button2Click(Sender: TObject);
var
 MyStream : TFileStream;
 MyStream2: TFileStream;
 ix : integer;
 S : Char;
const
   ASC_EBC : array[0..255] of byte = (
       $00, $01, $02, $03, $37, $2D, $2E, $2F,     { 00H-07H }
       $16, $05, $25, $0B, $0C, $0D, $0E, $0F,     { 08H-0FH }
       $10, $11, $12, $13, $3C, $3D, $32, $26,     { 10H-17H }
       $18, $19, $3F, $27, $1C, $1D, $1E, $1F,     { 18H-1FH }
       $40, $4F, $7F, $7B, $5B, $6C, $50, $7D,     { 20H-27H }
       $4D, $5D, $5C, $4E, $6B, $60, $4B, $61,     { 28H-2FH }
       $F0, $F1, $F2, $F3, $F4, $F5, $F6, $F7,     { 30H-37H }
       $F8, $F9, $7A, $5E, $4C, $7E, $6E, $6F,     { 38H-3FH }
       $7C, $C1, $C2, $C3, $C4, $C5, $C6, $C7,     { 40H-47H }
       $C8, $C9, $D1, $D2, $D3, $D4, $D5, $D6,     { 48H-4FH }
       $D7, $D8, $D9, $E2, $E3, $E4, $E5, $E6,     { 50H-57H }
       $E7, $E8, $E9, $4A, $E0, $5A, $5F, $6D,     { 58H-5FH }
       $79, $81, $82, $83, $84, $85, $86, $87,     { 60H-67H }
       $88, $89, $91, $92, $93, $94, $95, $96,     { 68H-6FH }
       $97, $98, $99, $A2, $A3, $A4, $A5, $A6,     { 70H-77H }
       $A7, $A8, $A9, $C0, $6A, $D0, $A1, $07,     { 78H-7FH }
       $04, $06, $08, $09, $0A, $14, $15, $17,     { 80H-87H }
       $1A, $1B, $20, $21, $22, $23, $24, $28,     { 88H-8FH }
       $29, $2A, $2B, $2C, $30, $31, $33, $34,     { 90H-97H }
       $35, $36, $38, $39, $3A, $3B, $3E, $41,     { 98H-9FH }
       $42, $43, $44, $45, $46, $47, $48, $49,     { A0H-A7H }
       $51, $52, $53, $54, $55, $56, $57, $58,     { A8H-AFH }
       $59, $62, $63, $64, $65, $66, $67, $68,     { B0H-B7H }
       $69, $70, $71, $72, $73, $74, $75, $76,     { B8H-BFH }
       $77, $78, $80, $8A, $8B, $8C, $8D, $8E,     { C0H-C7H }
       $8F, $90, $9A, $9B, $9C, $9D, $9E, $9F,     { C8H-CFH }
       $A0, $AA, $AB, $AC, $AD, $AE, $AF, $B0,     { D0H-D7H }
       $B1, $B2, $B3, $B4, $B5, $B6, $B7, $B8,     { D8H-DFH }
       $B9, $BA, $BB, $BC, $BD, $BE, $BF, $CA,     { E0H-E7H }
       $CB, $CC, $CD, $CE, $CF, $DA, $DB, $DC,     { E8H-EFH }
       $DD, $DE, $DF, $E1, $EA, $EB, $EC, $ED,     { F0H-F7H }
       $EE, $EF, $FA, $FB, $FC, $FD, $FE, $FF);    { F8H-FFH }
 
begin
  if OpenDialog1.Execute then begin
   MyStream:= TFileStream.Create(OpenDialog1.FileName,fmOpenReadWrite);
   MyStream.Position:= 0;
   MyStream2:= TFileStream.Create('c:\test2.txt',fmOpenReadWrite);
   MyStream2.Position:= 0;
 
   MyStream.Position:= 0;
 
   for ix:= 0 to MyStream.Size-1 do
   begin
     MyStream.ReadBuffer(S,1);
 
     s:=  Chr(ASC_EBC[Ord(s)]);
     MyStream2.WriteBuffer(s,1);
 
   end;
   MyStream2.Position:= 0;
 
   MyStream2.Free;
   MyStream.Free;
 end;
end;

Open in new window

0
MerijnBSr. Software EngineerCommented:
You can never do a full conversion because you're limited to what EBCDIC can do in a singe codepage.
0
puckoAuthor Commented:
So the correct way is to Go from UTF-8 to ansi with a specified codepage and then from ansi to EBCDIC with a specified translation map that is cortrect for each codepage?
0
MerijnBSr. Software EngineerCommented:
Yes
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.