读书人

Clipboard中文串解决办法

发布时间: 2012-01-24 23:11:54 作者: rapoo

Clipboard中文串
可以利用以下代码,实现将大于255的粘贴板文本复制到数组,如何处理中文字符串?
Dim bArr() As Byte
bArr = StrConv(Clipboard.GetText, vbUnicode)
Debug.print bArr

[解决办法]
给你另种思路

添加 Text1 Text2 Text3 Command1 Command2

Text1输入中文字符串, 当然使用 StrArray = StrConv(Clipboard.GetText, vbFromUnicode)也可

点击 Command1 将Text1转为二进制导入Text2

点击 Command2 将Text2还原为中文导入Text3
'**********************************************************

Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Dim i&, RetStr$, S
Dim NumArray() As Byte
Dim StrArray() As Byte
Private Sub Command1_Click()
If Trim(Text1.Text) = "" Then Exit Sub
RetStr = ""
StrArray = StrConv(Text1.Text, vbFromUnicode)
'StrArray = StrConv(Clipboard.GetText, vbFromUnicode)
For i = LBound(StrArray) To UBound(StrArray)
RetStr = RetStr & Replace(Format(CStr(Hex(StrArray(i))), "@@"), " ", "0") & " "
Next i
Text2.Text = Trim(RetStr)
End Sub

Private Sub Command2_Click()
If Trim(Text2.Text) = "" Then Exit Sub
S = Split(Trim(Text2.Text), " ")
ReDim NumArray(UBound(S)) As Byte
For i = LBound(S) To UBound(S)
NumArray(i) = Val("&H" & S(i))
Next i
RetStr = String((UBound(NumArray) + 1) * 2, 0)
CopyMemory ByVal StrPtr(RetStr), ByVal VarPtr(NumArray(0)), UBound(NumArray) + 1
RetStr = StrConv(RetStr, vbUnicode)
Text3.Text = Trim(RetStr)
End Sub



读书人网 >VB

热点推荐