zoukankan      html  css  js  c++  java
  • c#模拟js escape方法(转)

    实现URI字符串转化成escape格式的字符

    public static string Escape(string s)

            {
                StringBuilder sb = new StringBuilder();
                byte[] ba = System.Text.Encoding.Unicode.GetBytes(s);
                for (int i = 0; i < ba.Length; i += 2)
                {
                    if (ba[i + 1] == 0)
                    {
                        //数字,大小写字母,以及"+-*/._"不变
                        if (
                              (ba[i] >= 48 && ba[i] <= 57)
                            || (ba[i] >= 64 && ba[i] <= 90)
                            || (ba[i] >= 97 && ba[i] <= 122)
                            || (ba[i] == 42 || ba[i] == 43 || ba[i] == 45 || ba[i] == 46 || ba[i] == 47 || ba[i] == 95)
                            )//保持不变
                        {
                            sb.Append(Encoding.Unicode.GetString(ba, i, 2));
     
                        }
                        else//%xx形式
                        {
                            sb.Append("%");
                            sb.Append(ba[i].ToString("X2"));
                        }
                    }
                    else
                    {
                        sb.Append("%u");
                        sb.Append(ba[i + 1].ToString("X2"));
                        sb.Append(ba[i].ToString("X2"));
                    }
                }
                return sb.ToString();
            }
    原地址:http://www.cnblogs.com/meceky/archive/2013/11/27/3445245.html
  • 相关阅读:
    REST framework框架的基本组件
    GIT如何根据历史记录回退代码
    如何查看磁盘存储空间
    git免密拉取代码
    windows好用的cmd命令
    git如何新建分支
    screen命令
    解决windows配置visual studio code调试golang环境问题
    转载一篇棒棒的AWK教程
    解决Creating Server TCP listening socket 54.179.160.162:7001: bind: Cannot assign requested address
  • 原文地址:https://www.cnblogs.com/ManchesterUnitedFootballClub/p/4579596.html
Copyright © 2011-2022 走看看