如何将字符串转换为 byte() vb.net?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42341304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to convert string to byte() vb.net?
提问by Qassam Mahmoud
error msg i got : system.byte{}
我得到的错误消息:system.byte{}
code :
代码 :
Module Module1
模块模块1
Sub Main()
Dim qassam As String = "mylove"
Dim lena As Byte() = System.Text.Encoding.Default.GetBytes(qassam)
Console.WriteLine(lena)
Console.ReadLine()
End Sub
End Module
终端模块
回答by Tim Schmelter
You have successfully encoded the string into a byte(). But you can't output this byte-array with Console.WriteLinebecause then only the type-name is written.
您已成功将字符串编码为byte(). 但是你不能输出这个字节数组,Console.WriteLine因为只有类型名被写入。
You could use:
你可以使用:
Console.WriteLine(String.Join(",", lena))
On .NET 2.0 you could use this approach:
在 .NET 2.0 上,您可以使用这种方法:
Dim lenaStrings = Array.ConvertAll(lena, Function(b) b.ToString())
Console.WriteLine(String.Join(",", lenaStrings))

