I have a String like the following:
"The answer is 1000"
I want to insert commas into the number 1000 without destroying the rest of the String.
NOTE: I also want to use this for other Strings of differing lengths, so substring(int index) would not be advised for getting the number.
The best way that I can think of is to use a regex command, but I have no idea how.
Thanks in advance!
The following formats all the non-decimal numbers:
e.g. if you call:
formatNumbers("The answer is 1000 1000000")Result is:
"The answer is 1,000 1,000,000"See:
NumberFormatandMatcher.appendReplacement().