المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Text file to multidimensional array help needed!



C# Programming
03-21-2010, 05:51 PM
I have a notepad text file that looks like this:

xxxxixxxxxcxxxxxxxxixxxxt
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx

25 across, 19 down...

And some code to read in the text file:

FileStream fs = File.OpenRead("maptest.txt");
StreamReader reader = new StreamReader(fs);
string x = string.Empty;
while (!reader.EndOfStream)
{
int y = reader.Read();
char z = (char) y;
if (z == 'x' || z == 'c' || z == 'i' || z == 't') x += z.ToString();
}

char[,] map = new char[25, 19];
int index = 0;
for (int row = 0; row < 25; row++)
{

for (int col = 0; col < 19; col++)
{
map[row, col] = x[index];
index++;
}

}My array "char[,] map = new char[25, 19]" is meant to store x and y cords of each character ie to find the first instance of the character "i" I can get its by referencing "map[4,0]".

My text reader is wrong and I need some help to read in the values into the array http://www.barakasoft.com/script/Forums/Images/smiley_laugh.gif