Java – how to filter strings using numbers, dots, and commas?
•
Java
OK, so there's a long string. I want to delete everything in it, except decimal numbers, commas and dots,
I tried:
str = str.replace("[^0-9\\.\\,]","");
But it was nothing
Can someone help me
thank you!
Solution
You do not need to escape characters in a character group You should also use replaceall()
str = str.replaceAll("[^0-9.,]+","");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码