Replace all whitespace characters

前端 未结 10 1068
北荒
北荒 2020-12-04 07:39

I want to replace all occurrences of white space characters (space, tab, newline) in JavaScript.
How to do so?

I tried:

str.replace(/ /gi, \"X\         


        
10条回答
  •  醉酒成梦
    2020-12-04 08:14

    Actually it has been worked but

    just try this.

    take the value /\s/g into a string variable like

    String a = /\s/g;
    
    str = str.replaceAll(a,"X");
    

提交回复
热议问题