January 30, 2016
How to Split a String in C#/CSharp
To split a string in C#/CSharp, we make use of Split method. This will take a character as parameter to split. In the below given example, we are passing an empty space as parameter.
using System;
namespace Hello_World
{
class Program
{
static void Main(string[] args)
{
string hello = "I love making tutorials.";
string[] multiple = hello.Split(' ');
foreach(string single in multiple)
{
Console.WriteLine(single);
}
}
}
}
using System;
namespace Hello_World
{
class Program
{
static void Main(string[] args)
{
string hello = "I love making tutorials.";
string[] multiple = hello.Split(' ');
foreach(string single in multiple)
{
Console.WriteLine(single);
}
}
}
}
using System; namespace Hello_World { class Program { static void Main(string[] args) { string hello = "I love making tutorials."; string[] multiple = hello.Split(' '); foreach(string single in multiple) { Console.WriteLine(single); } } } }