How to convert part of a string between two indexes to uppercase in Node.js

1 Answer

0 votes
function convert_part_to_uppercase(str, start, end) {
    // Extract the part of the string before the start index
    const before = str.substring(0, start);
    
    const upperPart = str.substring(start, end).toUpperCase();
    
    // Extract the part of the string after the end index
    const after = str.substring(end);
    
    return before + upperPart + after;
}
        
    
let s = "node.js programming";
  
s = convert_part_to_uppercase(s, 3, 6);
console.log(s); 
 
s = convert_part_to_uppercase(s, 13, 14);
console.log(s); 

    
    
/*
run:
     
nodE.Js programming
nodE.Js progrAmming
     
*/

 



answered Sep 30, 2024 by avibootz
...