替换空间来连字符 [英] Replace Space to Hyphen
问题描述
我想更换一个空格字符到一个连字符我在我的字符串。
字符串replaceText =AT AT;
replaceText.replace('',' - ');
但是当我这样做,我似乎无法取代的角色。我试过的replaceAll()
方法,它也不行。
++++++回答+++++++
对不起我的错......深夜节目的结果:(
感谢您的回答,我不能大概回答所有的,所以我将检查的第一个答案
replaceText = replaceText.replace('',' - ');
replaceText = replaceText.replace('',' - ');
字符串是不变,它们不能被创建后改变。不知怎的,修改字符串的所有方法都将返回一个新字符串纳入了修改。
I am trying to replace a space character into a hyphen I have in my string.
String replaceText = "AT AT";
replaceText.replace(' ', '-');
but when I do this, I cannot seem to replace the character. I tried the replaceAll()
method and it doesn't work either.
++++++Answer+++++++
sorry my mistake.. the result of late night programming :(
thanks for the answer i cant probably answer all so i will check the first answer
replaceText = replaceText.replace(' ', '-');
replaceText = replaceText.replace(' ', '-');
Strings are immutable, they cannot be changed after creation. All methods that somehow modify a string will return a new string with the modifications incorporated.
这篇关于替换空间来连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!