LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

[点晴永久免费OA].net版URLEncode、ASP版URLDecode,支持汉字编码/解码

admin
2022年5月5日 18:55 本文热度 1711
ASP版URLDecode:
function URLDecode(strIn)
  URLDecode = ""
  Dim sl: sl = 1
  Dim tl: tl = 1
  Dim key: key = "%"
  Dim kl: kl = Len(key)

  sl = InStr(sl, strIn, key, 1)
  Do While sl>0
    If (tl=1 And sl<>1) Or tl<sl Then
URLDecode = URLDecode & Mid(strIn, tl, sl-tl)
    End If

    Dim hh, hi, hl
    Dim a
    select Case UCase(Mid(strIn, sl+kl, 1))
      Case "U":                  'Unicode URLEncode
      a = Mid(strIn, sl+kl+1, 4)
      URLDecode = URLDecode & ChrW("&H" & a)
      sl = sl + 6

      Case "E":                   'UTF-8 URLEncode
      hh = Mid(strIn, sl+kl, 2)
      a = Int("&H" & hh)          'ascii码
      If Abs(a)<128 Then
        sl = sl + 3
        URLDecode = URLDecode & Chr(a)
      Else
        hi = Mid(strIn, sl+3+kl, 2)
        hl = Mid(strIn, sl+6+kl, 2)
        a = ("&H" & hh And &H0F) * 2 ^12 Or ("&H" & hi And &H3F) * 2 ^ 6 Or ("&H" & hl And &H3F)
        If a<0 Then a = a + 65536
        URLDecode = URLDecode & ChrW(a)
        sl = sl + 9
      End If
    Case Else:                      'Asc URLEncode
      hh = Mid(strIn, sl+kl, 2)   '高位
      a = Int("&H" & hh)          'ascii码
      If Abs(a)<128 Then
      sl = sl + 3
      Else
      hi = Mid(strIn, sl+3+kl, 2) '低位
      a = Int("&H" & hh & hi)     '非ascii码
      sl = sl + 6
      End If
      URLDecode = URLDecode & Chr(a)
    End select

    tl = sl
    sl = InStr(sl, strIn, key, 1)
  Loop

  URLDecode = URLDecode & Mid(strIn, tl)
End function

.net版URLEncode:
       //对网址进行UrlEncode编码,为确保中文不乱码,接收后进行URLDecode解码
        public static string UrlEncode(string str)
        {
            StringBuilder sb = new StringBuilder();
            byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str);
            for (int i = 0; i < byStr.Length; i++)
            {
                sb.Append(@"%" + Convert.ToString(byStr[i], 16));
            }
            return (sb.ToString());
        }

        //对网址进行UrlEncode编码,为确保中文不乱码故意将%替换为了$,接收后先将$替换为%,然后再进行URLDecode解码
        public static string UrlEncode_change(string str)
        {
            StringBuilder sb = new StringBuilder();
            byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str);
            for (int i = 0; i < byStr.Length; i++)
            {
                sb.Append(@"$" + Convert.ToString(byStr[i], 16));
            }
            return (sb.ToString());
        }

该文章在 2022/5/5 18:55:55 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved