How to convert part of a string to uppercase start from specific index in C#

1 Answer

0 votes
using System;
using System.Text;
 
class Program
{
    static string convert_part_to_uppercase(string s, int idx) { 
        int len = s.Length; 
  
        if (idx < 0 || idx > len) return s;
  
        StringBuilder sb = new StringBuilder(s);
        
        for (int i = 0; i < len; i++) {
            if (i >= idx && (s[i] >= 'a' && s[i] <= 'z')) {
                sb[i] = Char.ToUpper(sb[i]);
            }
        }
        return sb.ToString();
    } 
    static void Main() {
        string s = "csharp programming"; 
  
        s = convert_part_to_uppercase(s, 4);
 
        Console.Write(s);
    }
}
 
 
 
 
/*
run:
 
cshaRP PROGRAMMING
 
*/

 



answered Nov 16, 2019 by avibootz
...