Replace Space to Hyphen

前端 未结 7 1114

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-19 00:03

    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.

提交回复
热议问题