Remove all spaces, carriage returns and newlines

//原始字符串
var string = "你好!\r\n 阳阳   坚持就是胜利";
  
//去掉所有的换行符
string = string.replace(/\r\n/g,"")
string = string.replace(/\n/g,"");
  
//去掉所有的空格(中文空格、英文空格都会被替换)
string = string.replace(/\s/g,"");
  
//输出转换后的字符串
console.log(string);

Guess you like

Origin blog.csdn.net/yf18040578780/article/details/127630584