Tuesday, 24 April 2018

split the string with regular expression using C#.

split the string with regular expression using C#.

Description:
In this example we explain that how to split the string with number in Asp.Net using C#. Or how to split the string with regular expression using C#. Or split string with regular expression in Asp.Net.


When I was working with one project at that time the client requirement was that if the string contain some number with bracket “)” then it must be split and display in new line.


Like suppose I have sting like “1) test one 2) test two 3) test 4) test 5) test) six"; then client want result like below

1) test one
 2) test two
3) test
 4) test
5) test) six

So to fulfil this demand I was found the one solution that will help you all to split the string with number using regular expression and display string in new line.so below is the code that will have used to split string with regular expression using C#.

Code: 

string[] arrs = Regex.Split(lblInformation.Text, @"\d+\)"); //lblInformation.Text contain the string like “1) test one 2) test two 3) test 4) test 5) test) six"

                    lblInformation.Text = string.Empty;
                    for (int i = 1; i < arrs.Length; i++)
                    {

                        lblInformation.Text += i + ")" + arrs[i] + "</br>";
                    }



0 comments:

Post a Comment