Monday, July 15, 2013

C# Split String Example in VB.NET | Split String with Special Characters (comma, underscore etc)

Introduction:

Here I will explain how to split string in
c#, vb.net using asp.net or split string with special characters in  c#vb.net or Split String with Comma, Space in  c#vb.net.
Description:
  
In previous posts I explained
Remove last character from string in C#, jQuery Remove first or last characters from string, SQL Server Query to remove first last characters from string, and many articles relating to Asp.net, c#, vb.net, JQuery. Now I will explain how to split string in c#, vb.net using asp.net.
To split string we need to write the code as shown below

Split String with one character in C#
protected void Page_Load(object sender, EventArgs e)
{
string istr = "Welcome to aspdotnet-suresh.com.";
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 aspdotnet-suresh.com."
Dim ostr As String() = istr.Split("-".ToCharArray())
For Each s As String In ostr
Response.Write(s & "<br/>")
Next
End Sub
Output of above code


Welcome to aspdotnet
suresh.com.
Split String with multiple characters in C#
protected void Page_Load(object sender, EventArgs e)
{
string istr = "welcome, to, aspdotnet-suresh.com.";
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, aspdotnet-suresh.com."
Dim ostr As String() = istr.Split(",-.".ToCharArray())
For Each s As String In ostr
Response.Write(s & "<br/>")
Next
End Sub
Output of above code

welcome
to
aspdotnet
suresh
com

source : http://www.aspdotnet-suresh.com/search/label/Asp.net?updated-max=2013-01-18T00%3A00%3A00%2B08%3A00&max-results=11

No comments:

Post a Comment