How to convert a word in a string to uppercase in TypeScript

2 Answers

0 votes
let str = "The Worlds most reliable Programming Q&A Site worlds";
  
str = str.replace(/worlds/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
0 votes
let str = "The Worlds most reliable Programming Q&A Site worlds";
  
const the_word = "Worlds";
 
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
...