0

If I have an bytes array for EBCDIC encoding, how can I convert it to a c# string?

I tried:

string str= Encoding.GetEncoding("EBCDIC").GetString(bytes);

string str= Encoding.GetEncoding("UTF-EBCDIC").GetString(bytes);

but got exception:

'EBCDIC' is not a supported encoding name

'UTF-EBCDIC' is not a supported encoding name

Is it a legacy encoding not supported in .Net anymore?

phuclv
  • 37,963
  • 15
  • 156
  • 475
kzfid
  • 688
  • 3
  • 10
  • 17
  • Does this answer your question? [C#: Convert COMP-3 Packed Decimal to Human-Readable Value](https://stackoverflow.com/questions/142972/c-convert-comp-3-packed-decimal-to-human-readable-value) – madreflection Jan 19 '23 at 04:28
  • 1
    TL;DR: `Encoding.GetEncoding(37)` for EBCDIC. – madreflection Jan 19 '23 at 04:28
  • @madreflection Thanks very much. Although not 100%, it gives me a hint. I need to call {Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);} first before getting the encoding. After calling, I can get the encoding by {Encoding.GetEncoding(37)} as you said or by {Encoding.GetEncoding("ibm037");}. I guess it depend on the running environment. For some environments where ibm037 exists by default, there is no need to call RegisterProvider. – kzfid Jan 19 '23 at 06:11
  • Ebcdic is a family of encodings, IBM037/cp037 is US-EBCDIC, ibm273/cp273 is german etc. – Bruce Martin Jan 19 '23 at 09:31

0 Answers0