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


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

Mar 13, 2013
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 stringSQL Server Query to remove first last characters from string, and many articles relating to Asp.netc#vb.netJQuery. 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 ObjectByVal 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 ObjectByVal 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

Comments