I need to read a string with non-space separated values (0-9). Why can't I use Empty literal in String.Split method?
// Reading Grid's row and col size
gridInputValues = Console.ReadLine().Split(' ');
gridRow = int.Parse(gridInputValues[0]);
gridCol = int.Parse(gridInputValues[1]);
gridMatrix2D = new int[gridRow, gridCol];
// Reading Grid's row * col matrix values
for( int r = 0; r < gridRow; r++ )
{
//string[] inputVal = Console.ReadLine().Split('');
//string[] inputVal = Console.ReadLine().Split(string.Empty));
string inputVal = Console.ReadLine();
for( int c = 0; c < gridCol; c++ )
{
//gridMatrix2D[r, c] = int.Parse(inputVal[c]);
gridMatrix2D[r, c] = int.Parse(inputVal[c].ToString());
}
Why not,
string[] inputVal = Console.ReadLine().Split('');
or
string[] inputVal = Console.ReadLine().Split(string.Empty));
works?
Alternatively, Is using string.ToString good practice in such case?
or
Will the string.ToString method on each iteration increase the running time?
EDIT 1:
Input:
"12345" // type is string
Expected Output:
"1","2","3","4","5" // type is string[]