static string ReplaceNumbers(string orgValue)
{
string rxPattern = @"\d+(?!\.)($|\s)";
var rx = new Regex(rxPattern, RegexOptions.IgnoreCase);
var res = rx.Replace(orgValue, delegate (Match match)
{
return match.ToString().Trim() + ". ";
});
rxPattern = @"(\.)[A-Za-z_]";
rx = new Regex(rxPattern, RegexOptions.IgnoreCase);
res = rx.Replace(res, delegate (Match match)
{
return match.ToString().Replace(".", ". ");
});
return res;
}
static void Main(string[] args)
{
Console.WriteLine(ReplaceNumbers("I Give you 5000"));
Console.WriteLine(ReplaceNumbers("I Give you 5000."));
Console.WriteLine(ReplaceNumbers("I cant give you 5000 please dont bother me."));
Console.WriteLine(ReplaceNumbers("I cant give you 5,000 and 1000 unit foods please dont bother me."));
Console.WriteLine(ReplaceNumbers("I cant give you 5000 , please dont bother me."));
Console.WriteLine(ReplaceNumbers("I cant give you 5000.Please dont bother me."));
//Result
//I Give you 5000.
//I Give you 5000.
//I cant give you 5000. please dont bother me.
//I cant give you 5,000. and 1000. unit foods please dont bother me.
//I cant give you 5000. , please dont bother me.
//I cant give you 5000. Please dont bother me.
}