开发者

How do I filter a string on just numbers, dots and commas?

开发者 https://www.devze.com 2023-03-05 16:16 出处:网络
Okay, so ive got a long string, and I want to remove everything thats inside, except for decimal numbers, comma\'s and dots,

Okay, so ive got a long string, and I want to remove everything thats inside, except for decimal numbers, comma's and dots,

I have tried:

str = str.replace("[^0-9\\.\\,]","");

But this just ends up in nothing开发者_运维问答..

Can anyone help me?

Thanks!


You don't need to escape the characters in the character group. You should also be using replaceAll().

str = str.replaceAll("[^0-9.,]+","");


Try str.replaceAll("[^0-9.,]+","");

0

精彩评论

暂无评论...
验证码 换一张
取 消