Kimtho6 Kimtho6 - 28 days ago 7
C# Question

Splitting a string with uppercase


Possible Duplicates:

Split a PascalCase string into separate words

is there a elegant way to parse a word and add spaces before capital letters




Is there a simple way to split this string
"TopLeft" to "Top" and "Left"

Answer

If you want it dynamic, meaning every time you find an upper case letter break it apart, I don't believe this is built in, but could be wrong; it's easy enough to write an extension method.

string output = "";

foreach (char letter in str)
{
   if (Char.IsUpper(letter) && output.Length > 0)
     output += " " + letter;
   else
     output += letter;
}