• 0

Searching a text file and displaying results VB.NET


Question

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

  • 0

Following steps should be able to achieve what you want....

- Collect text from file as string

- Break up the string to an array using M as marker

- Run through the array and check for the string you are after using regex

- Display or collect the ones that match

Link to comment
Share on other sites

  • 0
Following steps should be able to achieve what you want....

- Collect text from file as string

- Break up the string to an array using M as marker

- Run through the array and check for the string you are after using regex

- Display or collect the ones that match

Hi sweetsam, first of all thanks for the reply, I thought I was over complicating it. However another question if I read in the whole file then split by the M wont that then split by any other M contained within the file e.g

stringarray() = split(filecontents, "M")

Or do you mean I should split every 10 lines (9 for the block and the M included) and if so how would I do this if I have one large string?

Thanks

Jigsaw

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.