Escape:
複製代碼 代碼以下:git
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();
} ui
Unescape:
複製代碼 代碼以下:.net
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();
} ip
在 .net 中還能夠這樣來調用: string
在程序集中引用Microsoft.JScriptit
複製代碼 代碼以下:foreach
Microsoft.JScript.GlobalObject.escape("");
Microsoft.JScript.GlobalObject.unescape("");
coding