How to insert spaces between words that start with capital in a string with C#

1 Answer

0 votes
using System;
  
class Program
{
    static String insert_spaces(string s) { 
        for (int i = 1; i < s.Length; i++) {
             if (s[i] >= 'A' && s[i] <= 'Z') { 
                 s = s.Insert(i, " ");
                 i++;
             }
        }
        return s;
    } 
    static void Main() {
        string s = "PythonJavaF#C++C#";
          
        s = insert_spaces(s);
          
        Console.Write(s);
    }
}
  
  
    
    
/*
    
Python Java F# C++ C#
    
*/

 



answered Jan 15, 2020 by avibootz
edited Jan 15, 2020 by avibootz
...