Reputation: 19
Using TextField to place double/integer numbers, want to change any number with "," to number with "." and remove multiple dots and commas.
String test = "0....,,,,,,,....754568";
test.replaceAll(<?IDK?>, ".");
<?IDK?>
means that I don't know what to put there.
Examples:
4,5 → 4.5
6,,,,2 → 6.2
0....,,,,,,,....754568 → 0.754568
7...2 → 7.2
Upvotes: 1
Views: 2818
Reputation: 2342
If you want to replace all .
or ,
by .
:
test.replaceAll("[.,]+", ".");
Upvotes: 6
Reputation: 1559
You can have a regular expression, for example, to identify numbers which have more than one dot or comma you can use the following :
\d+[.,]{2,}+\d
You can adjust it based on your needs.
If you want to test it, this website is useful : https://www.freeformatter.com/java-regex-tester.html
Upvotes: 0