public static System.String encode(System.String toEncode)
{
System.Text.StringBuilder buffer = new System.Text.StringBuilder(toEncode.Length); //empty but initial capicity of 'length'
System.String temp;
char currChar;
for (int i = 0; i < toEncode.Length; i++)
{
currChar = toEncode[i];
if ((((int) currChar <= 0x1F) || ((int) currChar == 0x7F) || (((int) currChar >= 0x80) && ((int) currChar <= 0xFF))) || ((currChar == '<') || (currChar == '>') || (currChar == '\"') || (currChar == '#') || (currChar == '%') || (currChar == '{') || (currChar == '}') || (currChar == '|') || (currChar == '\\') || (currChar == '^') || (currChar == '~') || (currChar == '[') || (currChar == '\'')) || ((currChar == ';') || (currChar == '/') || (currChar == '?') || (currChar == ':') || (currChar == '@') || (currChar == '=') || (currChar == '&')))
{
temp = System.Convert.ToString(currChar, 16);
if (temp.Length == 1)
buffer.Append("%0" + temp);
//if(temp.length()==2) this can only be two or one digit long.
else
buffer.Append("%" + System.Convert.ToString(currChar, 16));
}
else
buffer.Append(currChar);
}
return buffer.ToString();
}