用大写字母分割字符串 [英] Splitting a string with uppercase
本文介绍了用大写字母分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法来拆分此字符串"TopLeft"到"Top"和"Left"
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;
}
这篇关于用大写字母分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文