If I have a string like
10,000kg crane,21
how should I strip all commas but the last to get
10000kg crane,21
I'm thinking this is a regular expression problem.
It can be done with regular expressions by using a lookahead assertion. You want to replace the commas that have at least one comma after them. The only comma for which this lookahead will fail is the last one.
Try this:
s = Regex.Replace(s, ",(?=.*?,)", "")
See it working online: ideone
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