String.Split() : split() method is used break a string into substring().
- Split(Char[ ], Int32, StringSplitOptions)
- Split(String[ ], Int32, StringSplitOptions)
- Split(String[ ], StringSplitOptions)
- Split(Char[ ], StringSplitOptions)
- Split(Char[ ], Int32)
- Split(Char[ ])
class Program
{
{
String str = "csharp, tutorial point";
String[ ] spearator = { "p, ", "tutorial" };
Int32 count = 2;
// using the method
String[ ] data = str.Split(spearator, count, StringSplitOptions.RemoveEmptyEntries);
foreach (String val in data)
{
System.Console.WriteLine(val);
}
}
}
Output :
cshar
point
2. Split(String[ ], Int32, StringSplitOptions)
class Program
{
{
// Taking a string
String str = "csharp, tutorial point";
String[ ] spearator = { "p, ", "tutorial" };
Int32 count = 2;
// using the method
String[ ] strlist = str.Split(spearator, count, StringSplitOptions.RemoveEmptyEntries);
foreach (String data in strlist)
{
System.Console.WriteLine(data);
}
}
}
Output :
cshar
point
3. Split(String[ ], StringSplitOptions)
class Program
{
{
String data= "csharp, tutorial point";char[ ] spearator = { ',', ' ' };
Int32 count = 2;
// Using the Method
String[ ] value= data.Split(spearator,count, StringSplitOptions.None);
foreach (String val in value)
{
System.Console.WriteLine(val);
}
System.Console.ReadLine();
}
}
Output :
csharp
tutorial point
csharp
tutorial point
4. Split(Char[ ], StringSplitOptions)
5. Split(Char[ ], Int32)
6. Split(Char[ ])
class Program
{
{
string data = "csharp-tutorial-point";
string[] value = data.Split('-');
foreach (var item in value)
{
System.Console.WriteLine(item);
}
}
}