当前位置: 移动技术网 > IT编程>开发语言>c# > C#版的 Escape() 和 Unescape() 函数分享

C#版的 Escape() 和 Unescape() 函数分享

2019年07月18日  | 移动技术网IT编程  | 我要评论
escape:
复制代码 代码如下:

public static string escape(string str)
{
stringbuilder sb = new stringbuilder();
foreach (char c in str)
{
sb.append((char.isletterordigit(c)
|| c == '-' || c == '_' || c == '\\'
|| c == '/' || c == '.') ? c.tostring() : uri.hexescape(c));
}
return sb.tostring();
}

unescape:
复制代码 代码如下:

public static string unescape(string str)
{
stringbuilder sb = new stringbuilder();
int len = str.length;
int i = 0;
while (i != len)
{
if (uri.ishexencoding(str, i))
sb.append(uri.hexunescape(str, ref i));
else
sb.append(str[i++]);
}
return sb.tostring();
}

另外, 在网上看到, 在 .net 中还可以这样来调用:
复制代码 代码如下:

microsoft.jscript.globalobject.escape("");
microsoft.jscript.globalobject.unescape("");

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网