Possible Duplicate:
An algorithm to "spacify" CamelCased strings
I have a string like this: MyUnsolvedProblem
I want to modify the string like this: My Unsolved Problem
How can I do that? I have tried using Regex with no luck!
To find all the uppercase characters in a string, call the replace() method on the string passing it a regular expression, e.g. str. replace(/[^A-Z]/g, '') . The replace method will return a new string containing only the uppercase characters of the original string.
Method #2 : Using enumerate() + isupper() In this, the indices are captured using enumerate(), and isupper() does task of uppercase check as in above method.
The java string toUpperCase() method returns the string in uppercase letter. In other words, it converts all characters of the string into upper case letter.
var result = Regex.Replace("MyUnsolvedProblem", @"(\p{Lu})", " $1").TrimStart();
Without regex:
var s = "MyUnsolvedProblem";
var result = string.Concat(s.Select(c => char.IsUpper(c) ? " " + c.ToString() : c.ToString()))
.TrimStart();
resultString = Regex.Replace("MyUnsolvedProblem", "([a-z])([A-Z])", "$1 $2");
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