Replace Space to Hyphen

前端 未结 7 1112

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:54

    The replace method returns a String, so you need to re-assign your string variable i.e.

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

提交回复
热议问题