在java语言中,有没有一种简单的方法从给定的String
中删除子字符串?
示例:"Hello World!"
,removing "o"
"Hell Wrld!"
→
发布于 2011-10-15 10:33:59
您可以很容易地使用String.replace()
String helloWorld = "Hello World!";
String hellWrld = helloWorld.replace("o","");
发布于 2014-01-30 20:57:33
您可以使用StringBuffer
StringBuffer text = new StringBuffer("Hello World");
text.replace( StartIndex ,EndIndex ,String);
发布于 2011-10-15 10:35:25
replace('regex', 'replacement');
replaceAll('regex', 'replacement');
在您的示例中,
String hi = "Hello World!"
String no_o = hi.replaceAll("o", "");
https://stackoverflow.com/questions/7775364
复制相似问题