I working with some EBCDIC data that I need to parse and find some Hex values. The problem that I'm having is that it appears that I'm reading the file in with the incorrect encoding. I can see that my record begins with "!
" (which is a x5A
in EBCDIC) but when doing the conversion to hex it returns as a x21
, which is the ASCII value for a "!
".
I was hoping that there was a built-in method in the framework, but I'm afraid that I'm going to have to create a custom class to correctly map the EBCDIC character set.
Using fileInStream As New FileStream(inputFile, FileMode.Open, FileAccess.Read)
Using bufferedInStream As New BufferedStream(fileInStream)
Using reader As New StreamReader(bufferedInStream, Encoding.GetEncoding(37))
While Not reader.EndOfStream
Do While reader.Peek() >= 0
Dim charArray(52) As Char
reader.Read(charArray, 0, charArray.Length)
For Each letter As Char In charArray
Dim value As Integer = Convert.ToInt16(letter)
Dim hexOut As String = [String].Format("{0:x}", value)
Debug.WriteLine(hexOut)
Next
Loop
End While
End Using
End Using
End Using
Thanks!