我有一个像 23.Piano+trompet
这样的字符串,我想使用这个函数从字符串中删除 23.
部分:
private String removeSignsFromName(String name) {
name = name.replaceAll(" ", "");
name = name.replaceAll(".", "");
return name.replaceAll("\\^([0-9]+)", "");
}
但它并没有这样做。此外,运行时也没有错误。
最佳答案
以下替换所有空白字符 (\\s
)、点 (\\.
) 和数字 (\\d
)使用 ""
:
name.replaceAll("^[\\s\\.\\d]+", "");
what if I want to replace the
+
with_
?
name.replaceAll("^[\\s\\.\\d]+", "").replaceAll("\\+", "_");
关于Java:从字符串中删除数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41505028/