Loading...
  所在位置:论坛首页 -> ┈┋电脑网络技术区┋┈ -> Asp/Asp.Net技术 -> 字符串和十六进制之间的转换方法
标题:字符串和十六进制之间的转换方法收藏 编辑 删除 楼主 | 上一篇 下一篇
你这是干嘛
等级:社区游民
权限:普通用户
积分:3
金钱:169
声望:4
经验:4
发帖数:35
注册:2008年4月20日
资料 短消息2008-6-7 10:46:30

1.C#中的代码

Color=#cccccc cellSpacing=0 cellPadding=1 width="80%" align=center bgColor=#ffffff border=1 heihgt="">
2.VB6中的代码
'*******************************************************************
 '<函数:Encode>
'作用:将字符串内容转化为16进制数据编码,其逆过程是Decode
'参数说明:
'strSource 需要转化的原始字符串
Public Function Encode(strEncode As String) As String
    Dim i As Long
    Dim chrTmp$
    Dim ByteLower$, ByteUpper$
    Dim strReturn$  '存储转换后的编码
   
    For i = 1 To Len(strEncode)
        chrTmp$ = Mid(strEncode, i, 1)
        ByteLower$ = Hex$(AscB(MidB$(chrTmp$, 1, 1)))
        If Len(ByteLower$) = 1 Then ByteLower$ = "0" & ByteLower$
        ByteUpper$ = Hex$(AscB(MidB$(chrTmp$, 2, 1)))
        If Len(ByteUpper$) = 1 Then ByteUpper$ = "0" & ByteUpper$
        strReturn$ = strReturn$ & ByteUpper$ & ByteLower$
    Next
   
    Encode = strReturn$
End Function
'</函数:Encode>

'*******************************************************************


'*******************************************************************
 '<函数:Decode>
'作用:将16进制数据编码转化为字符串,是Encode的逆过程
Public Function Decode(strDecode As String) As String
    Dim i As Long
    Dim strCode$ '存储转换后的编码
    Dim chrTmp$
   
    On Error GoTo ErrProc
   
    If Len(strDecode) Mod 4 <> 0 Then GoTo ErrProc
    For i = 1 To Len(strDecode) Step 4
        strCode = Mid$(strDecode, i, 4)
        chrTmp$ = ChrW("&H" & strCode)
        If chrTmp$ = "?" Then If strCode <> "003F" Then GoTo ErrProc
        Decode = Decode & chrTmp$
    Next
   
    Exit Function
ErrProc:
    Decode = strDecode
    DealwithEvents "不能解析的消息:" & strDecode
End Function
'</函数:Decode>

2008-6-7 10:46:30 顶部
第1页 共页 共0个回复     <<    >>    
 快速回复
  • 支持UBB,HTML标签

  • 高级回复

  • 操作选项:评分 加精 解精 奖惩 设专题 设公告 解公告 固顶 总固顶 解固顶 结帖 解结帖 锁帖 解锁 移帖 删帖
      首页 | 购买指南 | 商业版本 | 虚拟主机 | 特色介绍 | 下载中心 | 支付方式
    Copyright 2004-2008 BBSGood.com Powered By: BBSGood.Speed Version 5.0
      咨询电话:0575-85513832、0575-85513825(传真)、7*24小时咨询服务:13606552007 不良信息举报中心 浙ICP备05029817号
      业务QQ:38958768、客服QQ1:415896239、客服QQ2:343896043、MSN:jccsxx@hotmail.com