如何通过追加和分裂句子来比较单词 [英] how to compare words by appending and also splitting in sentence
问题描述
我有一个csv文件,里面有单词。在每列中,文件有一个单词,有些列有两个单词。我有一个句子,我分成了单词,我必须将句子中的单词与csv文件中的单词进行比较,并获得句子和csv文件中的单词。我可以比较单个单词,但有些行在csv文件中有两个单词,如let stay;确保 e.t.c所以我必须附加两个单词并进行比较,并将单词分开并单独进行比较。怎么做 。这种方法是正确的吗?
为什么不使用string.Contains方法迭代你的csv的每一列,而不是将句子分成单个单词文件?
示例代码:
string my_sentence = 快速的棕色狐狸跳过懒狗;
List< string> found_string_collection = new List< string>();
string [] csv_column_text = { fox, dog, 跳过, 快速};
foreach ( string text in csv_column_text)
{
if (my_sentence.Contains(text))
{
found_string_collection。添加文字);
}
}
< / string > < / string > 跨度>
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?
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:
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>
这篇关于如何通过追加和分裂句子来比较单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!