0
我试图在列表中找到单词。我有一个带有单词搜索的数组,我有一个带有单词的字符串,我有一个List,我正在添加字母。查找数组中的单词?
我想查找包含在数组搜索中的单词,在列单词收集中寻找。
我该怎么做?
我正在试着这个。
private string[] search = {"CAKE", "COFFEE"}; //words to search
private string wordFind = "CAKE"; //word find
private List<String> wordsCollected = new List<string>(); //add letters
/** add letters - A B C D E F G H .... */
public void addWordsCollected(string p){
if(!wordsCollected.Contains(p)){
wordsCollected.Add(p);
}
}
/** check if wordFind is found */
public bool isWordFound(){
bool found = false;
for (int x = 0; x < wordsCollected.Count; x++){
found = wordsCollected[x].IndexOf(wordFind);
if(found >= 0){
break;
found = true;
}
}
return found;
}
}
搜索阵列有什么用?使用wordFind有什么用? – brz 2014-10-04 21:11:38
你能否提供更多的上下文?我不明白你在做什么。 – BradleyDotNET 2014-10-04 21:13:18
在isWordFound()中,你有一个bool变量“found”,并且在“for”循环中你将它误用为int,而不是bool。你需要两个不同的变量。 – RenniePet 2014-10-04 21:18:59