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