Maybe someone can help me with this. I'm needing C# code that reliably does the following: given a string of characters, it returns a substring of characters. If the substring has an improperly formatted decimal number, that is the returned substring. Otherwise it returns a zero-length string.
So, as examples, it would detect the following in string "abc3. 04xta": -> returns "3. 04"
And for this string: "3bcd4 0. 25z10": returns "4 0. 25"
What I'm ultimately wanting is for the code to do a string.replace( ) that fixes the misformatting:
"abc3. 04xtra" becomes "abc3.04xtra", and "3bcd4 0. 25z10" becomes "3bcd40.25z10".
I know regular expressions is probably the way to go, but I'm having trouble getting my head around them.
The method I'd like would either return the poorly formatted "decimal number" substring; or, optionally,
it could fix the formatting in that substring and replace all occurrences in the larger string.
The end result is that it would turn this sentence...
"The bread was $3 .49, and it had always been $2 .15 before."
...into the following...
"The bread was $3.49, and it had always been $2.15 before."