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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...