How to split the sentence on basis of space in asp.net?


Hi
In so many time, we will get requirement to split the sentence into words. We can split the sentence on basis of space 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;

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

}

protected void Button1_Click(object sender, EventArgs e)
{
string str = TextBox1.Text;
//split the string o basis of ‘ ‘ (space)
string[] words= str.Split(‘ ‘);
foreach (string s in words)
{
Label1.Text += s + "<br/>";
}
}
}

Advertisement

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.