问题:读一个文本文件,以二进制输出(实际上是十六进制)。
如,一个以ascii编码的文件内容为 "abc 测", 我要输出显示为"61 62 63 B2 E2".
本来我想这样做的:
Private Sub Text1_Change()
Text2.Text = ""
For i = 1 To Len(Text1.Text)
bChar = MidB(Text1.Text, i, 1)
c = Int(Asc(bChar) / 16) & (Asc(bChar) Mod 16)
Text2.Text = Text2.Text + " " + c
Next i
Text2.Refresh
End Sub
但是MidB这句话有错,如果用Mid,对于中文又无法辨认。请VB版的高手指点一下,谢谢!
如,一个以ascii编码的文件内容为 "abc 测", 我要输出显示为"61 62 63 B2 E2".
本来我想这样做的:
Private Sub Text1_Change()
Text2.Text = ""
For i = 1 To Len(Text1.Text)
bChar = MidB(Text1.Text, i, 1)
c = Int(Asc(bChar) / 16) & (Asc(bChar) Mod 16)
Text2.Text = Text2.Text + " " + c
Next i
Text2.Refresh
End Sub
但是MidB这句话有错,如果用Mid,对于中文又无法辨认。请VB版的高手指点一下,谢谢!
解决方案 »
- 关于字符串截取的问题。
- VB程序打包:需含注册码(根据机器码来验证)、升级程序及网址。
- 能把如下代码转换到vb.net(正常运行)的请进入
- 那位朋友能找个READPROCESSMEMORY 读取其他程序可以直接运行的代码?
- WORD中有关单元格合并后的表格问题
- 高分求购通用刻录机源代码。
- 可不可以更新API的涵数库?
- 动态装载复选框控件,求例程,
- 请教高手!高分送上!!关于SQLSERVER7.0里怎样知道那些表被操作过的问题!
- 十万火急!!距离考试只有10个小时了,还有几题搞不懂??高分征解,一定给分!!<<<试题三>>>
- 兄弟们,打印预览怎么做呀?急
- 如何监视 局域网 里数据的传输 ??????????????
Dim bytData() As Byte
Dim i As Long
Text2.Text = ""
If Text1.Text = "" Then
Exit Sub
End If
bytData = StrConv(Text1.Text, vbFromUnicode)
Text2.SelText = Hex(bytData(0))
For i = 1 To UBound(bytData)
Text2.SelText = " "
Text2.SelText = Hex(bytData(i))
Next i
End Sub
Private Declare Function lopen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function lread Lib "kernel32" Alias "_lread" (ByVal hFile As Long, lpBuffer As Any, ByVal wBytes As Long) As Long
Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As LongConst READAPI = 0 ' Flags for _lopen
Const WRITEAPI = 1
Const READ_WRITE = 2Private Sub Form_Load()
Dim hFile As Long
Dim FLen As Long
Dim str As String
Dim lBuffer As Long
Dim i As Long
i = 1
FLen = FileLen("C:\2.txt")
hFile = lopen("C:\2.txt", READAPI)
If IsNumeric(hFile) Then '如果打开成功
While i <= FLen
lread hFile, lBuffer, 1
str = str & " " & Hex(lBuffer)
i = i + 1
Wend
MsgBox str
End If
End Sub
Text2.Text = ""
For i = 1 To Len(Text1.Text)
intChar = MidB(Text1.Text, i, 1)
strTmp = Hex(intChar)
If intChar < 0 Then '双字节文字
Text2.Text = Text2.Text + " " + Left(strTmp, 2) + " " + mid(strTmp, 3,2)
Else
Text2.Text = Text2.Text + " " + strTmp
End If
Next i
Text2.Refresh
End Sub
Private Sub Text1_Change()
Text2.Text = ""
For i = 1 To Len(Text1.Text)
intChar = Chr(Mid(Text1.Text, i, 1))
strTmp = Hex(intChar)
If intChar < 0 Then '双字节文字
Text2.Text = Text2.Text + " " + Left(strTmp, 2) + " " + Mid(strTmp, 3,2)
Else
Text2.Text = Text2.Text + " " + strTmp
End If
Next i
Text2.Refresh
End Sub
intChar = Asc(Mid(Text1.Text, i, 1))