VB中Unicode的转换

VB本身的字符串格式就是Unicode,用Winsock发送字符串的话,会默认把字符串转换为Ansi的格式进行发送。Ansi格式,对于英文符号等仍然使用单字节,汉字使用双字节。如果需要进行转换的话,可以用StrConv来进行。

如:

Dim byteFileName() As Byte

byteFileName = StrConv(m_filename, vbFromUnicode) ' Convert string.

不过如果要发送Unicode格式的字符串的话,这样是不行的,实际发送的是ansi的。其实如果要发送unicode的字符串的话,只要这样就可以了。

Dim s() As Byte

s = "abc你好" ' Convert string.

ws.SendData s