知道一个字符的unicode值,怎样得到这个字符?

maskX 2004-10-25 11:11:44
如题

就是类似 c# 里的
string ss="\u307b\u308b\u305a\u3042\u306d";

在VB.NET 里面怎么实现?
...全文
130 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
捏造的信仰 2004-10-26
  • 打赏
  • 举报
回复
'将整数转换为byte数组:
Public Function ToBytes(ByVal v As Integer) As Byte()
Dim b(-1) As Byte
Do
ReDim Preserve b(b.Length)
b(b.Length - 1) = v Mod 256
v = v / 256
Loop While v >= 1
If b.Length Mod 2 = 1 Then
ReDim Preserve b(b.Length)
b(b.Length - 1) = 0
End If
Return b
End Function


'得到Unicode字符
dim Result as string = Encoding.Unicode.GetString(ToBytes(Value))
cancersyf 2004-10-26
  • 打赏
  • 举报
回复
参考--

http://www.mblogger.cn/dotnet.mblogger.cn/net/posts/1243.htm
水如烟 2004-10-25
  • 打赏
  • 举报
回复
[Visual Basic]
Imports System
Imports System.IO
Imports System.Globalization
Imports System.Text

Public Class Encoding_UnicodeToCP
Public Shared Sub Main()
' Converts ASCII characters to bytes.
' Displays the string's byte representation in the
' specified code page.
' Code page 1252 represents Latin characters.
PrintCPBytes("Hello, World!", 1252)
' Code page 932 represents Japanese characters.
PrintCPBytes("Hello, World!", 932)

' Converts Japanese characters.
PrintCPBytes("\u307b,\u308b,\u305a,\u3042,\u306d",1252)
PrintCPBytes("\u307b,\u308b,\u305a,\u3042,\u306d",932)
End Sub

Public Shared Sub PrintCPBytes(str As String, codePage As Integer)
Dim targetEncoding As Encoding
Dim encodedChars() As Byte

' Gets the encoding for the specified code page.
targetEncoding = Encoding.GetEncoding(codePage)

' Gets the byte representation of the specified string.
encodedChars = targetEncoding.GetBytes(str)

' Prints the bytes.
Console.WriteLine("Byte representation of '{0}' in CP '{1}':", _
str, codePage)
Dim i As Integer
For i = 0 To encodedChars.Length - 1
Console.WriteLine("Byte {0}: {1}", i, encodedChars(i))
Next i
End Sub
End Class

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧