社区
Java SE
帖子详情
怎么样将byte数组转换成String?
xiaochongvip
2006-06-21 03:37:32
如我的byte数组数据为{1,2,97,98,96,98}我想转成String ,其中97按照ascii表为字符a
,98为字符c,应该怎么装换?
我可不想String转换为1297989698的,这样没办法看。
谢谢。
...全文
1161
6
打赏
收藏
怎么样将byte数组转换成String?
如我的byte数组数据为{1,2,97,98,96,98}我想转成String ,其中97按照ascii表为字符a ,98为字符c,应该怎么装换? 我可不想String转换为1297989698的,这样没办法看。 谢谢。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
xiaochongvip
2006-06-21
打赏
举报
回复
楼上行。谢谢.
forevertraveller
2006-06-21
打赏
举报
回复
byte[] a = {1,2,97,98,96,98} ;
StringBuffer s1=new StringBuffer(128);
s1.append("the final result:");
for (int i=0;i<a.length ;i++ )
{
s1.append((char)a[i]);
}
System.out.println(s1);
xiaochongvip
2006-06-21
打赏
举报
回复
都不行啊。
函数传进来的是byte数组
商科程序员
2006-06-21
打赏
举报
回复
就这样就行呀!
char[] c = new char[] {1,2,97,98,96,98};
System.out.println(new String(c));
输出结果是: ab`b
bjskyhorse
2006-06-21
打赏
举报
回复
// 字节数据转换为可打印字符串
// 如:{0xC8, 0x32, 0x9B, 0xFD, 0x0E, 0x01} --> "C8329BFD0E01"
// pSrc: 源数据指针
// pDst: 目标字符串指针
// nSrcLength: 源数据长度
// 返回: 目标字符串长度
int Bytes2String(const unsigned char* pSrc, char* pDst, int nSrcLength)
{
const char tab[]="0123456789ABCDEF"; // 0x0-0xf的字符查找表
for(int i=0; i<nSrcLength; i++)
{
// 输出低4位
*pDst++ = tab[*pSrc >> 4];
// 输出高4位
*pDst++ = tab[*pSrc & 0x0f];
pSrc++;
}
// 输出字符串加个结束符
*pDst = '\0';
// 返回目标字符串长度
return nSrcLength * 2;
}
kevinliuu
2006-06-21
打赏
举报
回复
byte[] a = {1,2,97,98,96,98} ;
String s = new String(a) ;
C#_
string
_
byte
数组转
换解析
C#
string
byte
数组转
换解析 C#
string
byte
数组转
换实现的过程是什么呢?C#
string
byte
数组间的转换需要注意什么呢?C#
string
byte
数组间转换所涉及的方法是什么呢?让我们来看看具体的内容: C#
string
byte
数组转
换之
string
类型转成
byte
[]:
byte
[]
byte
Array = System.Text.Encoding.Default.Get
Byte
s ( str ); 反过来,
byte
[]转成
string
:
string
str = System.Text.Encoding.Default.Get
String
(
byte
Array ); 其它编码方式的,如System.Text.UTF8Encoding,System.Text.UnicodeEncoding class等;例如:
string
类型转成ASCII
byte
[]:("01" 转成
byte
[] = new
byte
[]{ 0x30, 0x31}) 1
byte
[]
byte
Array = System.Text.Encoding.ASCII.Get
Byte
s ( str ); ASCII
byte
[] 转成
string
:(
byte
[] = new
byte
[]{ 0x30, 0x31} 转成 "01") 2
string
str = System.Text.Encoding.ASCII.Get
String
(
byte
Array ); 有时候还有这样一些需求:
byte
[] 转成原16进制格式的
string
,例如0xae00cf, 转
换成
"ae00cf";new
byte
[]{ 0x30, 0x31}转成"3031":
delphi-
string
互相转化为
byte
数组
delphi-
string
互相转化为
byte
数组
一个
byte
数组与字符串转化类库
这个类库可以实现 1.转换一个
String
字符串为
byte
数组 2.将字节
数组转
化为
String
类型的数据 3.转换一个int为
byte
数组 4.从字节数组中指定的位置读取一个Integer类型的数据 5.转换一个shor字符串为
byte
数组 6.从字节数组中指定的位置读取一个Short类型的数据
String
(含Hex)与
Byte
数组互相转换[代码]
1.字符串(
String
)与
Byte
[] 的互相转换. 2.Hex(
String
形式)与
Byte
[] 的互相转换.
Go-此工具用于将16进制字符串转
换成
10进制
byte
数组
此工具用于将16进制字符串转
换成
10进制
byte
数组
Java SE
62,615
社区成员
307,307
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章