You can try the following:
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
...
private string HexToStringMatchEvaluator(Match match)
{
int intValue = int.Parse(match.Groups[1].Value, NumberStyles.AllowHexSpecifier);
return Convert.ToChar(intValue).ToString();
}
...
string source = "ab\\x01c";
source = Regex.Replace(source, @"\\x(\d\d)", HexToStringMatchEvaluator);
byte[] bytes = Encoding.ASCII.GetBytes(source);
A brief explanation:
Regex.Replace looks for occurences of \x followed by two digits and passes each Match to our custom MatchEvaluator. The evaluator converts the specified value from hex to decimal and then to its equivalent Unicode character. The rest is obvious, I hope.
Hope this helps.