private static string TryEncodeLastSlash(string original)
{
var regexPattern = @"\\+$";
string result = Regex.Replace(original, regexPattern,
delegate(Match match)
{
string matchText = match.ToString();
return matchText + matchText; //double up the slashes
});
return result;
}