从字节数组转换为字符串 [英] convert from byte array to string
本文介绍了从字节数组转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
here is my code
int Appno= 0X0A0A0A0A;
byte[] Apps_Num_bytes = ConvertInt32ToByteArray((int)Appsno);
i希望将此转换为字符串,因为我希望输出像0A0A0A0A
或直接从int Appno转换为字符串0A0A0A0A
请帮帮我
谢谢
bipul pandey
i want to convert this to string as i want the output comes like "0A0A0A0A"
or direct from int Appno to string like "0A0A0A0A"
please help me
thanks
bipul pandey
推荐答案
说到字符串表示,编码 [ ^ ]很重要。它告诉计算机您是否需要ASCII,UTF8或其他。像这样使用:
When it comes to string representations, the Encoding[^] is important. It tells the computer whether you want ASCII, UTF8, or whatever. Use it like this:
string stringRepresentation = System.Text.Encoding.ASCII.GetString(Apps_Num_bytes);
int Appno = 0X0A0A0A0A;
string s1 = BitConverter.ToString(BitConverter.GetBytes(Appno))。替换( - ,);
-----------输出------------
0A0A0A0A
int Appno = 0X0A0A0A0A;
string s1 = BitConverter.ToString(BitConverter.GetBytes(Appno)).Replace("-","");
-----------Output------------
0A0A0A0A
尝试这个.........
try this.........
int Appno = 0x0004EB9C;
//int Appno = 0X0A0A0A0A;
string final = "";
string s = BitConverter.ToString(BitConverter.GetBytes(Appno));
string[] arr = s.Split('-');
for (int i = 0; i < arr.Length; i++)
{
char[] charArray = arr[i].ToCharArray();
Array.Reverse(charArray);
final = final + new string(charArray);
}
char[] charArray2 = final.ToCharArray();
Array.Reverse(charArray2);
final= new string(charArray2);
MessageBox.Show(final);
您希望输出的最终字符串变量....
your desire output in final string variable....
这篇关于从字节数组转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文