How to trim a string in TypeScript

2 Answers

0 votes
let s: string = "    typescript php nodejs                ";
 
s = s.replace(/(^\s*)|(\s*$)/g, '');
   
console.log(s);
   
   
   
/*
run:
   
"typescript php nodejs"
   
*/
 

 



answered Jul 6, 2024 by avibootz
0 votes
let s: string = "    typescript php nodejs                ";
 
s = s.trim();
   
console.log(s);
   
   
   
/*
run:
   
"typescript php nodejs"
   
*/

 



answered Jul 6, 2024 by avibootz
...