/////////////// c#
///////// Method 1.
///////// Method 2.
///////////////////// RESULT
I Love My India
///////// Method 1.
public string String_SplitWithUpperCase(string Str)
{
var r = new
System.Text.RegularExpressions.Regex(@"
(?<=[A-Z])(?=[A-Z][a-z]) |
(?<=[^A-Z])(?=[A-Z]) |
(?<=[A-Za-z])(?=[^A-Za-z])",
System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
return r.Replace(Str, " ");
}
///////// Method 2.
public string String_SplitWithUpperCase(string Str)
{
var r =System.Text.RegularExpressions.Regex.Matches(Str, @"([A-Z][a-z]+)")
.Cast<System.Text.RegularExpressions.Match>()
.Select(m => m.Value);
string result = string.Join("
", r);
}
///////// Method 3.
///////// Method 3.
public string String_SplitWithUpperCase(string Str)
{
var r = new
System.Text.StringBuilder();
foreach (var ch in Str)
{
if (char.IsUpper(ch)
&& r.Length > 0)
{
r.Append(' ');
}
r.Append(ch);
}
return r.ToString();
}
/////////////// Call function
/////////////// Call function
public void
getstring()
{
string result= String_SplitWithUpperCase("ILoveMyIndia");
}
///////////////////// RESULT
I Love My India
No comments:
Post a Comment