如何提取一个字符串的UNICODE编码?(用vb.net或者C#)
帮帮忙啊 大侠们!在线等待啊 unicode --------------------编程问答-------------------- 如果是VB就很简单dim s as string
dim B() as byte
s=.......
b=s
这样,b数组中,每相邻两个字节的值,就是对应s字符的Unicode妈 --------------------编程问答-------------------- 不是啦,例如‘一’,unicode码是4E00,我想得到的这个 --------------------编程问答--------------------
你有没有试?试都不试!
Private Sub Command3_Click()
Dim s As String
Dim B() As Byte
s = "一个人"
B = s
Dim i As Long
For i = 0 To UBound(B)
Debug.Print Hex(B(i))
Next
End Sub
结果是:
0
4E
2A
4E
BA
4E
--------------------编程问答-------------------- B能等于s吗 类型不一样。 --------------------编程问答-------------------- 兄弟 加QQ聊比较方便吧!我的是2469431738 redsky --------------------编程问答--------------------
我狂晕,能不能你去试一下不就知道了,都给你了历程,给你结果,还这么问!! --------------------编程问答-------------------- 哎 兄弟我已经试了!
我也截图上去了 我用的是vb.net 你说的是。。。。。? --------------------编程问答-------------------- 晕,我是VB6
.net的字符串应该有 .tobyte 之类的转换函数, --------------------编程问答-------------------- 我还有几个问题想问大侠您,能加QQ详聊吗?2469431738,感谢万分啊! --------------------编程问答-------------------- 有问题就把问题放出来,在这边讨论 --------------------编程问答-------------------- ?hex(ascw("一"))
4E00 --------------------编程问答-------------------- 参考: http://blog.csdn.net/chenjl1031/article/details/6059767
Option Explicit
Private Declare Function MultiByteToWideChar Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, ByVal lpWideCharStr As String, ByVal cchWideChar As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
Private Const CP_ACP As Long = 0
Private Const CP_UTF8 As Long = 65001
'Ansi纯文本文件转换为Unicode(Little Endian)文本文件
Private Function AnsiToULE(ByVal Inputansifile As String, ByVal OutputULEfile As String) As Boolean
Dim Filebyte() As Byte, sAnsi As String, retLen As Long, FileNumber As Long
Dim sUnicodeBuffer As String
On Error Resume Next
'打开Ansi纯文本文件Inputansifile
FileNumber = FreeFile
If Dir(Inputansifile) = "" Then AnsiToULE = False: Exit Function
Open Inputansifile For Binary As #FileNumber
ReDim Filebyte(LOF(FileNumber) - 1)
Get #FileNumber, , Filebyte
Close #FileNumber
sAnsi = StrConv(Filebyte, vbUnicode) '转换为VB6可显示的字符串
retLen = MultiByteToWideChar(CP_ACP, 0, sAnsi, LenB(sAnsi), vbNullChar, 0) '取得转换后需要的空间大小retLen
sUnicodeBuffer = String$(LenB(sAnsi), vbNullChar) '设置缓冲区大小
If retLen > 0 Then
retLen = MultiByteToWideChar(CP_ACP, 0, sAnsi, LenB(sAnsi), sUnicodeBuffer, retLen) '开始转换
Else
AnsiToULE = False: Exit Function
End If
'保存为Unicode(Little Endian)文本文件OutputULEfile
If retLen > 0 Then
FileNumber = FreeFile
If Dir(OutputULEfile) <> "" Then Kill (OutputULEfile)
Open OutputULEfile For Binary As #FileNumber
Put #FileNumber, , &HFEFF '加上Unicode(Little Endian)文件头BOM标志FFFE
Put #FileNumber, , sUnicodeBuffer '保存文件内容
Close #FileNumber
AnsiToULE = True
Else
AnsiToULE = False: Exit Function
End If
End Function
'Ansi纯文本文件转换为Unicode Big Endian文本文件
Private Function AnsiToUBE(ByVal Inputansifile As String, ByVal OutputUBEfile As String) As Boolean
Dim Filebyte() As Byte, Fbyte() As Byte
Dim sAnsi As String, retLen As Long, FileNumber As Long
Dim sUnicodeBuffer As String
Dim i As Long
On Error Resume Next
'打开Ansi纯文本文件Inputansifile
FileNumber = FreeFile
If Dir(Inputansifile) = "" Then AnsiToUBE = False: Exit Function
Open Inputansifile For Binary As #FileNumber
ReDim Filebyte(LOF(FileNumber) - 1)
Get #FileNumber, , Filebyte
Close #FileNumber
sAnsi = StrConv(Filebyte, vbUnicode) '转换为VB6可显示的字符串
retLen = MultiByteToWideChar(CP_ACP, 0, sAnsi, LenB(sAnsi), vbNullChar, 0) '取得转换后需要的空间大小retLen
sUnicodeBuffer = String$(LenB(sAnsi), vbNullChar) '设置缓冲区大小
If retLen > 0 Then
retLen = MultiByteToWideChar(CP_ACP, 0, sAnsi, LenB(sAnsi), sUnicodeBuffer, retLen) '开始转换
Else
AnsiToUBE = False: Exit Function
End If
'保存为Unicode Big Endian文本文件OutputUBEfile
If retLen > 0 Then
ReDim Filebyte(LenB(sAnsi) - 1), Fbyte(LenB(sAnsi) - 1)
Filebyte = StrConv(sUnicodeBuffer, vbFromUnicode)
For i = 0 To UBound(Filebyte)
If i Mod 2 = 0 Then
Fbyte(i) = Filebyte(i + 1)
Else
Fbyte(i) = Filebyte(i - 1)
End If
Next
FileNumber = FreeFile
If Dir(OutputUBEfile) <> "" Then Kill (OutputUBEfile)
Open OutputUBEfile For Binary As #FileNumber
Put #FileNumber, , &HFFFE '加上Unicode(Big Endian)文件头BOM标志FEFF
Put #FileNumber, , Fbyte ' sUnicodeBuffer '保存文件内容
Close #FileNumber
AnsiToUBE = True
Else
AnsiToUBE = False: Exit Function
End If
End Function
补充:VB , 网络编程