Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i had a csv file which has words in it. in each column the file has one word and some columns have two words . i have a sentence which i had splitted in to words and i have to compare the words in sentence with the words in csv file and get which words present in sentence and also in csv file . i am able to compare for single word but some rows are having two words in csv file like "let stay" made sure" e.t.c so i have to append two words and compare it and also split the words and compare individually . how to do that . is this approach correct?
Posted
Updated 24-May-15 23:33pm
v3
Comments
Abhipal Singh 25-May-15 5:39am    
Is there any issue if you could split multiple words into multiple columns?
for ex:
"let stay" in one cell will be changed to "let" and "stay" in two different cells.

1 solution

Instead of splitting the sentence in to single words, why don't you use string.Contains method and iterate through each column of your csv file ?

Sample Code:

C#
string my_sentence = "The quick brown fox jumps over the lazy dog";

            List<string> found_string_collection = new List<string>();

            string[] csv_column_text = { "fox", "dog", "jumps over", "quick" };

            foreach (string text in csv_column_text)
            {
                if (my_sentence.Contains(text))
                {
                    found_string_collection.Add(text);
                }
            }

</string></string>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900