This is my filing function that takes data from the file and places it in the array:
public void populate_grid_by_file()
{
String store_data_from_fil
you are splitting the data into lines, and it appears your intention in the inner loop is to process the characters in the current line. However, you are actually processing the entire file for each line iteration, which is why your output contains all the file's characters * the number of lines. Try this adjustment instead:
public void populate_grid_by_file()
{
String store_data_from_file = string.Empty;
try
{
using (StreamReader reader = new StreamReader("data.txt"))
{
store_data_from_file = reader.ReadToEnd().ToString();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
string[] line = store_data_from_file.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < line.Length; i++)
{
//string[] alphabet = store_data_from_file.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
string[] alphabet = line[i].Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries)
for (int j = 0; j < alphabet.Length; j++)
{
Sodoku_Gri[i, j] = alphabet[j];
}
}
}