1、源起:
KV需要解析从插件传来的URL网址,因为其可能经过编码,所以需要解码。
初用System.Web.HttpUtility.UrlDecode()这个函数,但根据用户环境crash场景,发现有.net framework库不全情况,即找不到System.Web.dll这个程序集。
居然有此等事情!
自写代码解析喽,在网上下载得System.Web源代码,抽离所需函数,满足需求,项目可以舍弃对System.Web的引用
2、UrlDecode(string str)
直贴代码以做备忘:
public static string UrlDecode(string str) { return UrlDecode(str, Encoding.UTF8); } static void WriteCharBytes(IList buf, char ch, Encoding e) { if (ch > 255) { foreach (byte b in e.GetBytes(new char[] { ch })) buf.Add(b); } else buf.Add((byte)ch); } static int GetInt(byte b) { char c = (char)b; if (c >= '0' && c <= '9') <