Ok a quick question for you all. I have a text file that has blocks of 9 lines that represent a screen like below, with the start denoted by an M:
M
Menu Title
Option 1
Option 2
Option 3
Option 4
Option 5
Option 6
Option 7
Option 8
M
Menu Title 2
Option 1
Option 2
Option 3
Option 4
Option 5
Option 6
Option 7
Option 8
and so on....
Now I want to search the text file for a specific string a user specifies. i can do this fine but I want to be able to display the block of 9 lines that the string is contained within. Now the string could be in several blocks so I would need to be able to show all blocks the string is in. What is the best way of doing this? I wondered if it would be to read the file line by line if it contains the string make a note of the line number and then somehow work out what block its in and then read each of the block lines and display them?
Question
Jigsaw
Hi All,
Ok a quick question for you all. I have a text file that has blocks of 9 lines that represent a screen like below, with the start denoted by an M:
M
Menu Title
Option 1
Option 2
Option 3
Option 4
Option 5
Option 6
Option 7
Option 8
M
Menu Title 2
Option 1
Option 2
Option 3
Option 4
Option 5
Option 6
Option 7
Option 8
and so on....
Now I want to search the text file for a specific string a user specifies. i can do this fine but I want to be able to display the block of 9 lines that the string is contained within. Now the string could be in several blocks so I would need to be able to show all blocks the string is in. What is the best way of doing this? I wondered if it would be to read the file line by line if it contains the string make a note of the line number and then somehow work out what block its in and then read each of the block lines and display them?
Any ideas?
Thanks in advance
Link to comment
Share on other sites
3 answers to this question
Recommended Posts