extract sentence based on words. C#

HI,
i  have text file and i want to extract sentences containing particular words and send it to a database

the problem is i have 6 arraylists and have the particular words their as they belong to 6 diff groups
i want to be able to loop through the text file get the sentences that belong to these groups based on the words in the arraylists and display each sentence, its group and the sentence after it.

am using c# vs 2008 .txt files

string uploadedFileName = TextBox1.Text;
        string uploadedFileFullPath = System.IO.Path.Combine(@"C:\DocUpload\", Path.GetFileName(uploadedFileName));
        StreamReader Filereader = File.OpenText(uploadedFileFullPath);
        string textline;
textline = Filereader.ReadToEnd();
        string[] sites = textline.Split(seperator);
        string[] commasite = textline.Split(commanseperator);
//string[] wordsToMatch;

        string[] wordsToMatch = (string[])cueContrast.ToArray(typeof(string));
        wordsToMatch.ToString().Split(' ');
        //wordsToMatch[0] = TextBox2.Text;

        // Find sentences that contain all the terms in the wordsToMatch array.

        // Note that the number of terms to match is not specified at compile time.

        var sentenceQuery = from sentence in commasite

                            let w = sentence.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',' },

                                                    StringSplitOptions.RemoveEmptyEntries)

                            where w.Distinct().Intersect(wordsToMatch).Any() == wordsToMatch.Any()

                            select sentence;

        foreach (string str in sentenceQuery)
        {

            Response.Write(str + ".");
            ListBox1.Items.Add(str);

        }

Open in new window

uddyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

uddyAuthor Commented:
ArrayList cueContrast = new ArrayList();
        cueContrast.Add("but");
        cueContrast.Add("whereas");
        cueContrast.Add("however");

it the array t
0
Alexandre SimõesManager / Technology SpecialistCommented:
What are you missing there on your code? The evaluation if the thing contains any of the words on the array?

Have a look at the attached code.

Cheers!
Alex
foreach (string k in cueContrast)
{
	if (sentence.Contains(k))
	{
		// do what you got to do with it.
	}

	// if you need it to be case insensitive the easiest way is this
	if (sentence.ToLower().Contains(k.ToLower()))
	{
		// do what you got to do with it.
	}
}

Open in new window

0
uddyAuthor Commented:
thanks i sorted it out
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alexandre SimõesManager / Technology SpecialistCommented:
You can always post your solution and mark it as the accepted answer.
This way you leave the question on the knowledge base with the correct solution that solved your problem.

Cheers!
Alex
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Algorithms

From novice to tech pro — start learning today.