可能重复:
Split a PascalCase string into separate words
is there a elegant way to parse a word and add spaces before capital letters分裂与大写的字符串
有没有一种简单的方法来拆分此字符串 “左上” 到 “顶” 和 “左”
可能重复:
Split a PascalCase string into separate words
is there a elegant way to parse a word and add spaces before capital letters分裂与大写的字符串
有没有一种简单的方法来拆分此字符串 “左上” 到 “顶” 和 “左”
如果你想要它是动态的,意味着每次你发现一个大写字母将它分开时,我不会相信这是内置的,但可能是错误的;编写扩展方法很容易。
string output = "";
foreach (char letter in str)
{
if (Char.IsUpper(letter) && output.Length > 0)
output += " " + letter;
else
output += letter;
}
好。我会使用StringBuilder而不是字符串进行修饰。 – 2010-11-02 15:27:58
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;
}
重复的问题http://stackoverflow.com/q/3216085/28736 – chilltemp 2010-11-02 15:24:34