How to Split a String based on delimiter in C# ?

There are times when you might want to split a string to array of strings based on delimiter in C#. This can be achieved by using the Split method defines in the string class.

How to Split a String with delimiter in C# ?

Below is a sample code snippet demonstrating how to split a string based on delimiter in C#.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace GinktageConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string InputString = "This is a test mesage from Ginktage.com";
            char[] delimitter = new char[]{',',' '};
            string[] OutputList = InputString.Split(delimitter);
            foreach (string outPutString in OutputList)
            {
                Console.WriteLine(outPutString);
            }
            Console.ReadLine();
        }     
    }
    
}

1

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...