Here is my txt file and i need to get x,y of O
####################
# #
# #
# #
# #
# #
# #
# O #
# #
####################
>Solution :
try this code:
int yIndex = 0;
using (var fileStream = File.OpenRead("t.txt")) //t.txt your input file
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true))
{
String line;
//read line by line and yIndex is added each time
while ((line = streamReader.ReadLine()) != null)
{
for(int i=0; i< line.Length;i++)
if(line[i]== 'O')
{
Console.WriteLine("X is: {0} Y is:{1}",i.ToString(),yIndex);
}
yIndex++;
}
}
result:
X is: 4 Y is:7