Escape: 複製代碼 代碼如下: public static string Escape(string str) { StringBuilder sb = new StringBuilder(); foreach (char c in str) { sb.Append((Char.IsLette ...
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
複製代碼 代碼如下:
Microsoft.JScript.GlobalObject.escape("");
Microsoft.JScript.GlobalObject.unescape("");