.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani

  

Split the string based on delimiter and display or store

   
 
     


Introduction :

In this tutorial we will learn how to split the sentence based on some delimiter like comma, semicolon ; or any other special characters or word even space using Split() method of string class in .NET Framework using C# and vb.net code example.

Using Split() Method of the string class you can split the sting based on the characters you want. In the below example I have shown you comma, similarly you can use other character to split like ;,/ etc. special characters or even characters even based on spaces.

C# Code sample:

using System;

namespace DotNetSpark.Tutorials
{
    class DotNetSpark
    {
        static void Main(string[] args)
        {
            // Declare the comma seperated string;
            string strValue = "DotNetSpark,Com,Tutorials";

            //Split the comma seperated value from the given string and store in a string type array variable 
            string[] arrValue = strValue.Split(",".ToCharArray());

            //using loop read the array stored value one by one
            foreach (string strDispay in arrValue)
            {
                Console.WriteLine(strDispay);
            }

            Console.ReadLine();
        }
    }
}

Output:

DotNetSpark
Com
Tutorials

VB.NET Code example:

Namespace DotNetSpark.Tutorials
	Class DotNetSpark
		Private Shared Sub Main(args As String())
			' Declare the comma seperated string;
			Dim strValue As String = "DotNetSpark,Com,Tutorials"

			'Split the comma seperated value from the given string and store in a string type array variable 
			Dim arrValue As String() = strValue.Split(",".ToCharArray())

			'using loop read the array stored value one by one
			For Each strDispay As String In arrValue
				Console.WriteLine(strDispay)
			Next

			Console.ReadLine()
		End Sub
	End Class
End Namespace

Output:

DotNetSpark
Com
Tutorials

Other Tutorials in the same Category:
      
  • How to find length or number of characters in a given string      
  • Compare two string using CompareTo Method of string class      
  • Check the word contains in a string or not?      
  • Merge or Concat two string value      
  • Check the string value Equals or not?      
  • Split the string based on delimiter and display or store      
  • Trim or remove white or extra spaces from given string      
  • Get the part or sub string from a given string      
  • Convert string into lowercase of a given string      
  • Convert all string into uppercase of a given string      
  • How to replace string with some other string value?      
  • Remove the specific character or word from a given string      
  • Insert word or characters at any position in a given string or sentence      
  • Display the reverse of the given string      
  • Find string, word or character in a given string      
  • Check the given string is null or empty

  •  
         
     
    Return to Main Index Page


    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend