Answer the question
In order to leave comments, you need to log in
How to split a string into elements in C#?
Error program:
string str = "one, two, three, four, five";
string[] num = str.Split(", ");
Console.WriteLine(num[0]);
Console.ReadLine();
Answer the question
In order to leave comments, you need to log in
If you carefully read MSDN Split , it turns out that an array of characters is passed to the method. Characters are separated by single quotes. What prevents you from passing an array of characters to the method?var num = str.Split(new [] {' ', ','});
var a = "one, two, three, four, five".Split( new[] { ", " }, StringSplitOptions.None );
foreach ( string b in a ) { Console.WriteLine( b ); };
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question