将Int32转换为String

时间:2018-01-29 19:36:12

标签: string vb.net int32

我有一小段代码将字符串转换为Int32

Dim sample As String = "H۩llo!"
For Each c As Char In sample
    Dim enc As String = Convert.ToInt32(c)
    Console.Write(enc + " ")
Next
Console.ReadKey()

这会将文本转换为Int32 输出:

72 1769 108 108 111 33

但有没有办法将输出转换回“H۩llo!”?

1 个答案:

答案 0 :(得分:3)

您可以使用

将其转换回原始字符串
Dim nums As Int32() = { 72, 1769, 108, 108, 111, 33 }
Dim cs As Char() = nums.Select(Function(x) Microsoft.VisualBasic.ChrW(x)).ToArray()
Dim s = New String(cs)
Console.OutputEncoding = System.Text.Encoding.UTF8
Console.WriteLine(s)