Splitting a string with uppercase [duplicate]
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"
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;
}
string s = "TopLeft";
List<int> splits = new List<int>();
for(int i=0; i<s.Length;i++)
if(char.IsUpper(s[i]))
splits.Add(i);
int splitstart = 0;
foreach (int split in splits)
{
s.Substring(splitstart, split);
splitstart = split;
}
精彩评论