在 android/java 中,我试图用 +
替换某些字符串中的空格,但它似乎不起作用。我做错了吗?
String string="Hello world";
string.replace(" ", "+");
最佳答案
String
对象是不可变的,因此 replace
方法不会更改字符串但会创建一个您必须重新保存的新字符串:
String string="Hello world";
string = string.replace(" ", "+");
关于java - android/java 中的字符串,replace() 什么都不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4730547/