How to convert part of a string between two indexes to uppercase in TypeScript

1 Answer

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

    
    
/*
run:
     
"typESCript programming" 
"typESCript prOgramming" 

*/

 



answered Sep 30, 2024 by avibootz
...