I need to replace some value in given text using c# preferably using regex
Input : This is sample text. I need to replace $100.00 value with new value.
Output : This is sample text. I need to replace $50.00 value with new value.
need to replace $100 to $50
Note: The number should be any size
solution:
this works for my requirement
Regex.Replace(“This is sample text. I need to replace $100.00 value with new value.”,
“\$\d+(\.\d+)?” , “50”, RegexOptions.IgnoreCase)
You should be able to use this:
Then just use the replace function.
If you need to be able to determine the value to replace dynamically, based on the matched number take a look at the MatchEvaluator.