Published on: 14 July, 2013

How to split string in ASP.Net C#

Posted by andy | 7812 views 1 likes 0 favourites 0 comments
Tumblr Digg Google Plus

There are two ways to split string in C# ASP.Net, you can use Regex to split the string if you want to split between words. But if you want to split only one single character, you can use the Split function from String object.

See below example for more details:

//first example split a single character
string sampleString = "1,2,3,4,5";
string[] arrayString = sampleString.Split(',');
foreach (string str in arrayString) {
	Response.Write(str + ", ");

//second example split a word
string sampleSentence = "Run and faster and go and higher";
string[] arrayWord = System.Text.RegularExpressions.Regex.Split(sampleSentence, "and");
foreach (string str in arrayWord) {
	Response.Write(str + ", ");

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.
Share your article with us and add your own google adsense account to earn extra money. Plus, you can promote a link back to your site.
Related Articles
Published on: 13 February, 2017
One thing to remember when publishing your ASP.Net web applications, you may find out, some files could be not completely published due to the settings on the file properties. One example that I had are some font types file. In order to fix this problem you can navigate to the files that are missing and right click the properties.
Published on: 11 May, 2016
The slidingExpiration attribute is used in ASP.Net form authentication. This property is used to reset the expiration time for a valid authentication cookie if a request that has already being made has passed the timeout interval. Which means, if it is already expires, the current user will require to re-authentication again.
Related Tutorials