以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  Ukey是不是只能写入字母和数字,汉字不能写入呢?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=69979)

--  作者:lhpc120
--  发布时间:2015/6/14 4:15:00
--  Ukey是不是只能写入字母和数字,汉字不能写入呢?
RT:

If UKey.Start() Then
    Dim
Val As String = "联想Lenovo"
    If
UKey.LenStrA(Val) > 50 Then
       
MessageBox.Show("用户名长度不能超过50个字节!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Else
        If
UKey.WriteStr(0,val,"46DFA0D7","C292C1DB") = True
           
MessageBox.Show("成功写入数据!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If
    End If
End If

采用官方的例子!也是写入失败!

首先确认,读写密码正确。    测试过N次,只要写入字母和数字都可以,就是不能写入汉字!

请官方给出解答!

--  作者:大红袍
--  发布时间:2015/6/14 10:21:00
--  

 嗯嗯,是的,中文字符还得进行转码存储,取出还得还原,如

 

 

Dim str As String = "联想Aabc"
Dim bs() As Byte = Encoding.Unicode.GetBytes(str)
Dim nstr As String = ""
For Each b As Byte In bs
    nstr &= b.ToString("x") & ","
Next
nstr = nstr.Trim(",")
output.show(nstr)

 

\'----------------转回去

 

Dim strAry() As String = nstr.Split(",")
Dim bys(strAry.Length-1) As Byte
For i As Integer = 0 To strAry.Length - 1
    Bys(i) = Byte.Parse(strAry(i), System.Globalization.NumberStyles.HexNumber)
Next
Dim bstr As String = Encoding.Unicode.GetString(bys)
output.show(bstr)