如何从给定字符串中删除子字符串?
有没有一种简单的方法可以从Java中的给定中删除子字符串?String
示例:,删除→"Hello World!"
"o"
"Hell Wrld!"
有没有一种简单的方法可以从Java中的给定中删除子字符串?String
示例:,删除→"Hello World!"
"o"
"Hell Wrld!"
你可以很容易地使用 String.replace()
:
String helloWorld = "Hello World!";
String hellWrld = helloWorld.replace("o","");
您可以使用 StringBuffer
StringBuffer text = new StringBuffer("Hello World");
text.replace( StartIndex ,EndIndex ,String);