Question Read specific character from text file

xilef

Member
Joined
Oct 31, 2009
Messages
6
Programming Experience
1-3
I have a block of text in a text .txt file that looks like this:
VB.NET:
....xxxxxxxxxxxxxxxxxxxxxxxxx...
....xxxxxxxxxxxxxxxxxxxxxxxxx...
...xxxxxxxxxxxxxxxxxxxxxxxxxx...
..xxxxxxxxxxxxxxxxxxxxxxxxxxx...
..xxxxxxxxxxxxxxxxxxxxxxxxxxxx..
...xxxxxxxxxxxxxxxxxxxxxxxxxx...
....xxxxxxxxxxxxxxxxxxxxxxxxxx..
.....xxxxxx..xxxxxxxxxxxxxxxxx..
......xxxxx...xxxxxxxxxxxxxxx...
The entire block of text has 32 lines and 32 characters per line (32x32 grid)
I want to make an if statement that targets specific characters using an x variable and a y variable.
EG:
VB.NET:
If character(x,y) = "x"
then
msgbox("Oh dear, an x")
elseif character(x,y) = "."
msgbox("Success! A .!")
endif
Can someone please help me?

I've tried reading every character and entering them into a 2D array (failed)
I've tried splitting them into individual lines and entering them into a 1D array (Success, but very difficult to target individual characters from this, and will take a long time to set up as I only did this for 10 lines)

EDIT: I'm using visual basic .net 2005 with .net framework 2.0
 
VB.NET:
Dim lines() As String = IO.File.ReadAllLines("grid.txt")
Dim x As Integer = 5, y As Integer = 5
If lines(x)(y) = "x"c Then
The x here index the lines String array, the y index the Char array of that line.
 
VB.NET:
Dim lines() As String = IO.File.ReadAllLines("grid.txt")
Dim x As Integer = 5, y As Integer = 5
If lines(x)(y) = "x"c Then
The x here index the lines String array, the y index the Char array of that line.
Thank you this works perfectly.
 
Back
Top