将 EBCDIC Char 转换为十六进制值(AFP EBCDIC 数据)
我正在处理一些 EBCDIC 数据,我需要解析这些数据并找到一些十六进制值。 我遇到的问题是,我似乎正在使用不正确的编码读取文件。 我可以看到我的记录以“!
”开头(这是 EBCDIC 中的 x5A
),但在转换为十六进制时,它返回为 x21
code>,这是“!
”的 ASCII 值。
我希望框架中有一个内置方法,但恐怕我必须创建一个自定义类来正确映射 EBCDIC 字符集。
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
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(3)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以这样做:
抱歉我啰嗦了。 这是可行的,但并不简单。
You can do it like this:
Sorry I was long-winded. It is doable, but not simple.