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+");
}
}