Break a pascal string into a logical set of words

I would like to take a pascal string like "CountOfWidgets" and convert it to something more convenient, like "Count of Widgets" in C #. Several adjacent uppercase characters must be left unchanged. What is the most efficient way to do this?

NOTE : Duplicate .NET. How can you split the caps? split the string into an array?

+6
string c # regex
source share
1 answer

I don’t know about the effective, but at least brief:

Regex r = new Regex("([AZ]+[az]+)"); string result = r.Replace("CountOfWidgets", m => (m.Value.Length > 3 ? m.Value : m.Value.ToLower()) + " "); 
+13
source share

All Articles