Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.Text.Encoding.EBCDIC ? 2

Status
Not open for further replies.

tgreer

Programmer
Oct 4, 2002
1,781
US
Doesn't C# support EBCDIC encoding?

I'm working on a project that involves parsing Xerox Metacode print streams, encoded as variable-byte EBCDIC records. The print stream data itself is in ASCII, but the record headers and control records are in EBCDIC.

I read the records in as byte arrays. I know I can convert a byte array into an ASCII string:

Code:
Encoding ascii = Encoding.ASCII;
char[] asciiChars;
string asciiString;

record = new Byte[record_size];
count = infile.Read(record,0,record_size);
asciiChars = new char[ascii.GetCharCount(record, 0, record.Length)];
ascii.GetChars(record, 0, record.Length, asciiChars, 0);
asciiString = new string(asciiChars);

Obviously not all the code is there, but that's enough to show the technique. I need to do the same thing with records I know are in EBCDIC, yet System.Text.Encoding doesn't have EBCDIC!?

Any idea how to turn a byte array into a string, using EBCDIC encoding?



Thomas D. Greer
 
Here is the VB version

Private oCulture As Globalization.CultureInfo = Threading.Thread.CurrentThread.CurrentCulture
Private m_Enc As System.text.Encoding = _
Text.Encoding.GetEncoding(oCulture.TextInfo.EBCDICCodePage)

- free online Compare/Diff of snippets
 
in C# that's:

Code:
private CultureInfo oCulture = Threading.Thread.CurrentThread.CurrentCulture();
private System.Text.Encoding m_Enc = Text.Encoding.GetEncoding(oCulture.TextInfo.EBCDICCodePage);

there's a section in the microsoft help that explains how to use this.


mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top