Split(); function in C#
This function is used to split a string into substrings on the basis of characters in an array. It returns a string array. The split method can be implemented by the declaring element inside the separator using a single code(' ')to split from. In the below program I have declared comma sign to split from (',').
Example
using System;
namespace program
{
class Program
{
static void Main(string[] args)
{
string str1 = ("One,Two,Three,Four,Five");
string[] str2 = str1.Split(','); /*Declared comma sign to split from (',')*/
foreach (string str3 in str2)
{
Console.WriteLine(str3);
}
Console.ReadKey();
}
}
}
Output
One
Two
Three
Four
Five
This function is used to split a string into substrings on the basis of characters in an array. It returns a string array. The split method can be implemented by the declaring element inside the separator using a single code(' ')to split from. In the below program I have declared comma sign to split from (',').
Example
using System;
namespace program
{
class Program
{
static void Main(string[] args)
{
string str1 = ("One,Two,Three,Four,Five");
string[] str2 = str1.Split(','); /*Declared comma sign to split from (',')*/
foreach (string str3 in str2)
{
Console.WriteLine(str3);
}
Console.ReadKey();
}
}
}
Output
One
Two
Three
Four
Five