Hello
I have a List that contain: “ABCDEFGHIJKLMNOPQRSTUVWXYZ”.
I need find words in this List, for example: CAKE, COFFEE, BALL, APPLE, and others.
I tried follow this example: http://msdn.microsoft.com/en-us/library/aa287730(v=vs.71).aspx
but doesn’t work.
I’m trying this.
private List<String> wordsCollected = new List<string>();
wordsCollected.Add("A");
wordsCollected.Add("B");
wordsCollected.Add("C");
wordsCollected.Add("D");
wordsCollected.Add("E");
wordsCollected.Add("F");
wordsCollected.Add("G");
wordsCollected.Add("H");
wordsCollected.Add("I");
wordsCollected.Add("J");
wordsCollected.Add("K");
//others
//word to find
private string wordToFind = "CAKE";
/**
* this method should find word CAKE
* Remember that List<string> have ABCDEFGHIJKL and not word CAKE
*/
public bool isWordFound(){
bool found = false;
foreach(string x in wordsCollected){
found = wordsCollected[x].IndexOf(wordToFind);
if(found > -1){
//CAKE IS FOUND
found = true;
}
}
return found;
}
}
How can I do this ?
Are you getting an error or is the code not working?
– cflowersTry changing line 21 to 24 to something like: found = wordsCollected[x].Contains(wordFind); if(found){ break; }
– ScribeI tried and still doesn't work :(
– ferpaWhat error are you getting
– cflowersI did:
– ferpaDebug.Log(wordsCollected[x].Contains(wordFind))does returns always false