Replace Space to Hyphen

前端 未结 7 1121

I am trying to replace a space character into a hyphen I have in my string.

String replaceText = \"AT AT\";
replaceText.replace(\' \', \'-\');

7条回答
  •  被撕碎了的回忆
    2021-02-18 23:50

    Strings are immutable. You need to use the return value from replace:

    replaceText = replaceText.replace(' ', '-');
    

提交回复
热议问题