How to split the sentence without special char in asp.net?


Hi
We can split the sentence without special char using “System.Text.RegularExpressions” namespace in c#. It also gives very good performance and easy to implement

Code behind code is like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

public partial class Program_SpliteStringUsingRegExp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string input = TextBox1.Text;
string[] w = splitword(input);
foreach (string s in w)
{
Label1.Text+=s+ "<br/>";
}

}

static string[] splitword(string s)
{
//it will split all non word character and return an array of character.
return Regex.Split(s, @"\W+");
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: