How to replace all occurrences of character in a string in TypeScript

3 Answers

0 votes
let s = "typescript php c++ PHP css";
    
s = s.replace(/p/g, "*");
 
console.log(s);
  
   
   
    
    
/*
run:
    
"ty*escri*t *h* c++ PHP css" 
   
*/

 



answered Jan 23, 2022 by avibootz
0 votes
let s = "typescript php c++ PHP css";
    
s = s.split('p').join('*');
 
console.log(s);
  
   
   
    
    
/*
run:
    
"ty*escri*t *h* c++ PHP css" 
   
*/

 



answered Jan 23, 2022 by avibootz
0 votes
let s = "typescript php c++ PHP css";
     
s = s.replace(/p/gi, "*");
  
console.log(s);
   
    
    
     
     
/*
run:
     
"ty*escri*t *h* c++ *H* css" 
    
*/

 



answered Jan 23, 2022 by avibootz
...