问题描述
您好,C#专家,
我正在尝试使用此代码将字符串转换为字节,但这给我提供错误提示.
i am trying to convert string to byte using this code, but it gives error pls help me..
public 静态 byte [] StringToByte( string InString ){
public static byte[] StringToByte(string InString) {
字符串 [] ByteStrings;
string[] ByteStrings;
ByteStrings = InString.Split(" .ToCharArray());
ByteStrings = InString.Split(" ".ToCharArray());
byte [] ByteOut;
byte[] ByteOut;
ByteOut = 新 byte [ByteStrings.Length-1];
ByteOut = new byte[ByteStrings.Length-1];
( int i = 0; i == ByteStrings.Length-1; i ++){
for (int i = 0;i==ByteStrings.Length-1;i++) {
ByteOut = Convert.ToByte(("0x" + ByteStrings ));
ByteOut = Convert.ToByte(("0x" + ByteStrings));
}
返回 ByteOut;
return ByteOut;
}
推荐答案
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte []个字节= Encoding.GetBytes(yourString);
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
Byte[] bytes = Encoding.GetBytes(yourString);
这篇关于如何在C#中将字符串转换为字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!