我只是想在Android中用另一个字符替换。我的代码:
et = (EditText) findViewById(R.id.editText1);
String str = et.getText().toString();
str.replace(' ','_');
et.setText(str);
System.out.println(str);
但是这里的“空格”没有被“下划线”代替。我也尝试了其他字符。
请帮忙!!
字符串在Java中是不可变的- replace
不更改现有字符串,它返回一个新字符串。你要:
str = str.replace(' ','_');
(这肯定是重复的,但是我现在没有足够的时间来找到合适的一个...)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句