Pages

Wednesday, 3 July 2013

How To Split String Example in VB.NET Or Split String with Special Characters (comma, underscore etc) in C# Asp.Net

How To Split String Example in VB.NET Or Split String with Special Characters (comma, underscore etc) in C# Asp.Net


Program:

.Aspx File:

Split String with one character in C#


protected void Page_Load(object sender, EventArgs e)
{
string istr = "Welcome to  fantasyaspnet.blogspot.in.";
string []ostr = istr.Split("-".ToCharArray());
foreach (string s in ostr)
{
Response.Write(s+"<br/>");
}
}

Split String with one character in VB.NET


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim istr As String = "welcome to fantasyaspnet.blogspot.in."
Dim ostr As String() = istr.Split(".".ToCharArray())
For Each s As String In ostr
Response.Write(s & "<br/>")
Next
End Sub

Output

Welcome to fantasyaspnet
blogspot
in.

Split String with multiple characters in C#


protected void Page_Load(object sender, EventArgs e)
{
string istr = "welcome, to, fantasyaspnet.blogspot.in.";
string []ostr = istr.Split(",-.".ToCharArray());
foreach (string s in ostr)
{
Response.Write(s+"<br/>");
}
}

Split String with multiple characters in VB.NET


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim istr As String = "welcome, to,  fantasyaspnet.blogspot.in."
Dim ostr As String() = istr.Split(",-.".ToCharArray())
For Each s As String In ostr
Response.Write(s & "<br/>")
Next
End Sub

Output

welcome
 to
 fantasyaspnet.blogspot.in

No comments:

Post a Comment