Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2009-04-23
5
Medium Priority
?
600 Views
Last Modified: 2012-05-06
Can someone help me with a routine to convert a utf-8 file to EBCDIC (in Delphi 2007)
0
Comment
Question by:pucko
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:louislietaer
ID: 24222294
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
 
LVL 1

Author Comment

by:pucko
ID: 24222343
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
 
LVL 19

Expert Comment

by:MerijnB
ID: 24222607
You can never do a full conversion because you're limited to what EBCDIC can do in a singe codepage.
0
 
LVL 1

Author Comment

by:pucko
ID: 24222621
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
 
LVL 19

Accepted Solution

by:
MerijnB earned 1000 total points
ID: 24222713
Yes
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

578 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