fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5.  
  6. // Original string array
  7. public static readonly string[,] first =
  8. {
  9. {"2", " ", " ", " ", "1"},
  10. {"2", " ", "4", "3", " "},
  11. {" ", "2", " ", "1", " "},
  12. {" ", "1", " ", "3", " "},
  13. {"1", " ", " ", " ", " "}
  14. };
  15.  
  16. public static void Main()
  17. {
  18.  
  19. // Convert
  20. int[,] second = new int[first.GetLength(0), first.GetLength(1)];
  21.  
  22. for (int j = 0; j < first.GetLength(0); j++)
  23. {
  24. for (int i = 0; i < first.GetLength(1); i++)
  25. {
  26. int number;
  27. bool ok = int.TryParse(first[j, i], out number);
  28. if (ok)
  29. {
  30. second[j, i] = number;
  31. }
  32. else
  33. {
  34. second[j, i] = 0;
  35. }
  36. }
  37. }
  38.  
  39. // Print in console
  40. for (int i = 0; i < second.GetLength(0); i++)
  41. {
  42. for (int j = 0; j < second.GetLength(1); j++)
  43. Console.Write(second[i, j] + "\t");
  44.  
  45. Console.WriteLine();
  46. }
  47.  
  48. Console.ReadLine();
  49. }
  50. }
Success #stdin #stdout 0.01s 29664KB
stdin
Standard input is empty
stdout
2	0	0	0	1	
2	0	4	3	0	
0	2	0	1	0	
0	1	0	3	0	
1	0	0	0	0