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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.