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"
To split a string on capital letters, call the split() method with the following regular expression - /(? =[A-Z])/ . The regular expression uses a positive lookahead assertion to split the string on each capital letter and returns an array of the substrings.
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
findall() method to split a string on uppercase letters, e.g. re. findall('[a-zA-Z][^A-Z]*', my_str) . The re. findall() method will split the string on uppercase letters and will return a list containing the results.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With