0

I want to make a program that will open a .txt file and search through the whole text file and output certain key words plus the next 8 characters (e.g "te_12345678") I would need to find everything starting with the te_ and then the next 8 chars would be a string of random numbers and letters. Then output it to a listbox.

How would i go about doing this,

Thanks,

Lewis

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by jonsca
0

Here's the heart of it. Adding it to the listbox is a matter of taking the substring 8 characters long after the indicies found. Text is a string found by reading all of the text file until the end.

List<int> intlist = new List<int>();
            string pattern = "te_";
            int index=-1,temp;  //index = -1 to start from zero below
            while(((temp = text.IndexOf(pattern,index+1))>0))
            {                              //when not found temp = -1
                intlist.Add(temp);
                index = temp;
            }

I'll let you have the rest of the fun. :) Post back with any questions.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.