How to replace all line breaks in a string with Node.js

2 Answers

0 votes
let s = `node.js
php
c++
css`;
 
console.log(s);
 
s = s.replace(/(\r\n|\r|\n)/g, ' ');
 
console.log(s);
   
    
    
     
     
/*
run:
     
node.js
php
c++
css
node.js php c++ css
    
*/

 



answered Jan 23, 2022 by avibootz
0 votes
let s = `node.js
php
c++
css`;
 
console.log(s);
 
s = s.split('\n').join(' ');
 
console.log(s);
   
    
    
     
     
/*
run:
     
node.js
php
c++
css
node.js php c++ css
    
*/

 



answered Jan 23, 2022 by avibootz
...