The approach to removing abusive characters is potentially problematic. What if there is more in the line . ? It will not be deleted, although it should!
Deleting non-digital digits or periods the string joe.smith ($3,004.50) converted to .3004.50 .
Imho, it's better to map a specific pattern and extract it using a group. It would be simple to find all adjacent commas, numbers and periods with a regular expression:
[\d,\.]+
Test run example:
Pattern understood as: [\d,\.]+ Enter string to check if matches pattern > a2.3 fjdfadfj34 34j3424 2,300 adsfa Group 0 match: "2.3" Group 0 match: "34" Group 0 match: "34" Group 0 match: "3424" Group 0 match: "2,300"
Then, for each match, remove all the commas and send them to the parser. To handle a case with something like 12.323.344 , you can do another check to see that the corresponding substring has at most one . .
Matthew Gunn Dec 03 '15 at 9:20 2015-12-03 09:20
source share