Splits the camel cased input text into separate words.

This is an example method to split "Camel Cased" into separated words.

Example Camel Cased

  • ThisIsOneExample
  • TomorrowIsWhatDay
  • ThisIsAnotherExample

ASPX Page

   <asp:Label ID="Label1" runat="server" Text="Camel Words"></asp:Label>:  
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Convert"
onclick="Button1_Click" />
<br />
Preview :
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<br />
<p>&nbsp;</p>
<p>&nbsp;</p>



Code Behind

 protected void Page_Load(object sender, EventArgs e)  
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string camelWords = TextBox1.Text;
IEnumerable<string> _words = SplitCamelCase(camelWords);
foreach (string a in _words)
{
Literal1.Text += a + " ";
}
}
/// <summary>
/// Splits the camel cased input text into separate words.
/// </summary>
/// <param name="text">Camel cased text</param>
public IEnumerable<string> SplitCamelCase(string text)
{
var matches = Regex.Matches(text, "[A-Z]+(?=[A-Z][a-z]|[0-9]|$)|[A-Z][a-z]+|[0-9]+");
return matches.Cast<Match>().Select(m => m.Value);
}


Example Output :





Popular posts from this blog

How to create zip file to download in JSP- Servlet

How to create DataGrid or GridView in JSP - Servlet

Pinging in ASP.NET Example