首 页源码商城图片动画下载中心文章中心轻年论坛客户留言赣州动漫收藏箱订单查询繁體中文
设为首页
加入收藏
联系我们
您当前的位置:轻年网 -> 文章中心 -> vb编程类 -> 多媒体技术 -> 文章内容 退出登录 用户管理
栏目导航
· 多媒体技术 · 图像色彩
· 网络通信 · 程序间通信
· 其它
热门文章
· 数字化的时钟
· 左边显示日历,右边显...
· 最简单的目录树形例...
· 非常酷的日历,相信不...
· 真正的全屏显示,只能...
· [转载] 企业网站更新的必要...
· [推荐] 营销型网站规划
· 可以计算出下载指定...
· 将系统装到U盘中 如...
· twunk32.exe木马的清...
相关文章
Byte数组与String互换
作者:未知  来源:本站整理  发布时间:2008-4-16 17:48:44  发布人:wonderful

减小字体 增大字体

请问VB中如何将Byte数组转换成String型?楼主yjg5(如风逐月)2005-03-04 14:35:21 在 VB / 基础类 提问
请问VB中如何将Byte数组转换成String型?
问题点数:20、回复次数:8
Top
 

1 楼myhgyp(也许是这样的,信不信由你)回复于 2005-03-04 14:40:01 得分 3Public   Sub   StringToByteArray(ByteArray()   As   Byte,   str   As   String,   size   As   Long)     'String转换成Byte数组  
          Dim   i   As   Long,   c   As   String,   icode   As   Integer  
           
          For   i   =   0   To   size   -   1  
                          ByteArray(i)   =   AscB(MidB(str,   i   +   1,   1))  
          Next   i  
           
  End   Sub  
   
  Public   Sub   ByteArrayToString(str   As   String,   hex()   As   Byte,   size   As   Long)   'Byte数组转换成String  
          Dim   i   As   Long,   c   As   Byte  
           
          str   =   ""  
          For   i   =   0   To   size   -   1  
                          str   =   str   &   ChrB(hex(i))  
          Next   i  
           
  End   Sub
Top

2 楼viena(维也纳N02)回复于 2005-03-04 14:43:50 得分 3如果Byte数组中存的是Unicode,直接赋值;  
  如果不是Unicode,用Strconv转换一下
Top

3 楼myhgyp(也许是这样的,信不信由你)回复于 2005-03-04 14:46:16 得分 3或:  
  Public   Function   StringToByteArray(str   As   String,   size   As   Long)   as   byte()   'String转换成Byte数组  
          Dim   i   As   Long,   c   As   String,   icode   As   Integer  
          Dim   ByteArray()   as   Byte  
          Redim   ByteArray(size)  
          For   i   =   0   To   size   -   1  
                          ByteArray(i)   =   AscB(MidB(str,   i   +   1,   1))  
          Next   i  
          StringToByteArray=ByteArray  
  End   Sub  
   
  Public   Function   ByteArrayToString(hex()   As   Byte,   size   As   Long)   As   String,   'Byte数组转换成String  
          Dim   i   As   Long,   c   As   Byte  
          str   =   ""  
          For   i   =   0   To   size   -   1  
                          str   =   str   &   ChrB(hex(i))  
          Next   i  
          ByteArrayToString=str  
  End   Sub  
 
Top

4 楼sinos_sinos(挑战不是障碍 人生处处精彩)回复于 2005-03-04 14:52:54 得分 3Dim   byteAry(10)   as   Byte    
  Dim   Str5   as   String  
  byteAry(0)   =   25    
  byteAry(1)   =   144    
  byteAry(2)   =   97    
  byteAry(3)   =   98  
  byteAry(4)   =   99    
  Str5   =   StrConv(byteAry,   vbUniCode)
Top

5 楼viena(维也纳N02)回复于 2005-03-04 14:54:13 得分 3楼上,Byte数组和String可以直接相互转换的  
   
          'VB中的String是Unicode  
          Dim   str1   As   String  
          Dim   str2   As   String  
          Dim   abyte1()   As   Byte  
          Dim   abyte2()   As   Byte  
          str1   =   "字符串abcd1234"  
          abyte1   =   str1  
          abyte2   =   StrConv(str1,   vbFromUnicode)  
           
          str2   =   abyte1  
          Debug.Print   "Unicode的byte数组直接赋值:"   &   str2  
          str2   =   abyte2  
          Debug.Print   "没转转换为Unicode是这样:"   &   str2  
          str2   =   StrConv(abyte2,   vbUnicode)  
          Debug.Print   "转换为Unicode就可以了:"   &   str2
Top

6 楼homezj(小吉)回复于 2005-03-04 14:56:16 得分 3viena说得对!  
  存放文本的Byte数组可以与String直接转换。  
   
  dim   a()   as   byte,s   as   string  
   
  ---------------------------  
  在内存中的相互转换  
   
  s="hggjh"  
  a=s   '直接转为Unicode编码的数组  
  s=a   '将Unicode编码的数组转为String  
  ----------------------------------  
   
  -------------------------------------------  
  对于存在文件中的文本,读入byte数组为ANSI编码  
   
  s=strconv(a,vbunicode)   '可将文件读入byte数组转为String  
  a=strconv(s,vbfromunicode)   '可将String转为ANSI编码存入byte数组  
  ------------------------------------------------------------  
  常用的转换就这些了  

 

[] [返回上一页] [打 印] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 管理登录
Copyright © 2006-2020 qn21.com. All Rights Reserved . 赣ICP备08002103号