public static string Encode(string source)
{
string tmp = "";
string pattern = @"(?:[a-z][a-z]*[0-9]+[a-z0-9]*)";
Regex rg = new Regex(pattern, RegexOptions.IgnoreCase);
foreach (char character in source)
{
byte charInByte = Convert.ToByte(character);
string hex = charInByte.ToString("x");
hex = "%" + hex.ToUpper();
string match = new string(character,1);
tmp += rg.Match(match).Success ? match : hex;
}
return tmp;
}