How to convert multiple words in a string to uppercase in TypeScript

2 Answers

0 votes
let str = "The Worlds most reliable Programming Q&A Site worlds";
  
const the_word = "Worlds|reliable";
 
const re = new RegExp(the_word, "gi");
  
str = str.replace(re, function UpperCase(s) { return s.toUpperCase(); });
   
console.log(str);
 
 
 
                    
/*
run:
  
"The WORLDS most RELIABLE Programming Q&A Site WORLDS" 
   
*/
  

 



answered May 22, 2022 by avibootz
0 votes
let str = "The Worlds most reliable Programming Q&A Site worlds";
  
str = str.replace(/Worlds|reliable/gi, function UpperCase(s) { return s.toUpperCase(); });
   
console.log(str);
 
 
 
                    
/*
run:
  
"The WORLDS most RELIABLE Programming Q&A Site WORLDS" 
   
*/
  

 



answered May 22, 2022 by avibootz
...