I am using Selenium(C#) on NUnit Framework and is getting a string from UI as $4850.19. I want to compare above string with the value from backend (DB) to assert they are equal. I am using a below method to parse my dollar amount from front-end, but the issue is that is also stripping the decimal point; and obviously the comparison with backend is failing.
Method used:
public static string RemoveNonNumeric(string s)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.Length; i++)
if (Char.IsNumber(s[i]))
sb.Append(s[i]);
return sb.ToString();
}
How to strip out any '$' or ',' but keep '.' in the value?
With Reg ex it's trivial
Regex.Replace(s, "[^0-9.]", "")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With