社区
C#
帖子详情
如何把string的内容转化为byte[]
ywcyj
2004-06-14 01:41:28
简单问题,大家看看
string a="12345678987654321";
byte[] b=new byte[0];
b=?
...全文
379
17
打赏
收藏
如何把string的内容转化为byte[]
简单问题,大家看看 string a="12345678987654321"; byte[] b=new byte[0]; b=?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
17 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wangjunhua24
2004-06-15
打赏
举报
回复
上面的老兄不错
killygirl
2004-06-14
打赏
举报
回复
我看上面不少都有问题,似乎有数据溢出啊……
stan0714
2004-06-14
打赏
举报
回复
上面说的都对,但是只能对English.
我给一个例子,汉字都可以的:
string aa="哈阿";
byte[] bt=new byte[0];
UnicodeEncoding ue=new UnicodeEncoding();
bt=ue.GetBytes(aa);
Console.WriteLine(aa);
string bb=ue.GetString(bt);
Console.WriteLine(bb);
亲密数
2004-06-14
打赏
举报
回复
string temp = "this is a test";
byte[] msg = Encoding.ASCII.GetBytes(temp);
这种方法可以
ywcyj
2004-06-14
打赏
举报
回复
呵呵,谢过各位
hbzxf
2004-06-14
打赏
举报
回复
a="ddddddddddddddd";
char[] b = a.ToCharArray();
liduke
2004-06-14
打赏
举报
回复
string.ToCharArray();
云孤天
2004-06-14
打赏
举报
回复
// 把十六进制字符串转换成字节型,返回字节型数组
public byte[] StringToByte(string InString)
{
string[] ByteStrings;
ByteStrings = InString.Split(" ".ToCharArray());
byte[] ByteOut;
ByteOut = new byte[ByteStrings.Length-1];
for (int i = 0;i==ByteStrings.Length-1;i++)
{
ByteOut[i] = Convert.ToByte(("0x" + ByteStrings[i]));
}
return ByteOut;
}
Piyongcai
2004-06-14
打赏
举报
回复
string temp = "this is a test";
byte[] msg = System.Text.Encoding.ASCII.GetBytes(temp);
jinbao
2004-06-14
打赏
举报
回复
Encoding
Lovest
2004-06-14
打赏
举报
回复
Encoding.GetBytes(String)
myxs
2004-06-14
打赏
举报
回复
byte[] msg = Encoding.ASCII.GetBytes(temp);
或者:
System.Convert.Tochar(string);
wzs_wzs123
2004-06-14
打赏
举报
回复
BitConverter.GetBytes
wnlovezxm
2004-06-14
打赏
举报
回复
=0
gengwei80
2004-06-14
打赏
举报
回复
string temp = "this is a test";
byte[] msg = Encoding.ASCII.GetBytes(temp);
daguzhang
2004-06-14
打赏
举报
回复
string a="d343";
char[] aToArray=a.ToCharArray();
Encoder enc=Encoding.Default.GetEncoder();
byte[] b=new byte[10];
enc.GetBytes(aToArray,0,aToArray.Length,b,0,false);
foreach( byte c in b)
MessageBox.Show(Convert.ToString(c));
athossmth
2004-06-14
打赏
举报
回复
string a="askdjfa;ldksfjwilgfj";
char[] c=a.ToCharArray();
Java中
byte
与
String
的相互
转化
博客主要围绕Java展开,介绍了
String
转化
为
byte
[]数组、
byte
[]数组
转化
为
String
字符串的
内容
,还提及了设置格式相关信息。
java
string
转
byte
_java中
String
类型的如何转为
byte
[]
本文介绍了在Java中如何将
String
转换为
byte
数组的两种方法:简单版和复杂版。简单版使用了默认字符编码,而复杂版则指定了UTF-8编码,展示了不同编码下字节数组的长度和
内容
。此外,还提供了一个将
Byte
数组
转化
为
String
的示例代码。
String
与其他数据类型的相互转换
本文详细介绍了Java中
String
与基本数据类型(如int、float等)之间的转换方法,包括Integer.parseInt()、
String
.valueOf()等关键函数的使用,并展示了如何将
String
转化
为字符数组char[]以及
Byte
数组,同时也演示了从这些数组回转到
String
的过程。
内容
涵盖了数据类型的相互转换及其在实际编程中的应用。
[转贴]将
Byte
数组
转化
为
String
文章指出FCL很多方法返回包含字符的
Byte
数组,而非
String
。介绍了将包含ASCII和Unicode编码字符的
Byte
数组转换为
String
的方法,还讨论了ASCIIEncoding和UnicodeEncoding类的Get
String
方法,该方法有多种重载方式,可将
Byte
数组部分字符转为
String
。
几种字符串到
byte
[] 数组
转化
为
String
的方法
博客涉及
string
、
byte
、encoding等信息技术概念,可能围绕它们的构造函数等方面展开,但因
内容
缺失,具体细节不明。
C#
111,129
社区成员
642,533
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章