Friday 2 October 2015

Splits the camel cased input text into separate words.

Leave a Comment
This is example method to split "Camel Cased" into seperated 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 :






By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.