Ok so im trying to put together a little function that will allow a person to type out a sentence, and it will then search for words that sound like numbers, and then list those numbers!
For instance someone enters the following sentence - "This is just one test sentence, for the next section I will talk about two different things!"
When you look through you can see the word "one", the word "for" and the word "two", so the output should read - 142
It would use a list of words like this -
string[] strNumWords = {"zero", "one", "won", "two", "too", "to", "three",
"four", "for", "fore", "five", "six", "seven" , "eight",
"ate", "nine", "nein"};
Im not really sure of the logic of putting this into practice as im fairly new to coding (clearly lol), so any clues would be great appreciated.
Im not entirely sure if I should be using arrays, lists or Dictionaries for this type of stuff.
The output im getting is looking like this - 124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124124
Its repeating and its not in the correct order! Driving me insane!
string[] strNumWords = {"zero", "one", "won", "two", "too", "to", "three",
"four", "for", "fore", "five", "six", "seven" , "eight",
"ate", "nine", "nein"};
int[] codeNumber = new int[100];
string codeSentence = "This is just for a quick test to see if one of these four numbers will show up.";
for (int i = 0; i < codeSentence.Length; i++)
{
if (codeSentence.Contains("one"))
{
Console.Write(1);
codeNumber[i] = 1;
}
if (codeSentence.Contains("won"))
{
Console.Write(1);
codeNumber[i] = 1;
}
if (codeSentence.Contains("two"))
{
Console.Write(2);
codeNumber[i] = 2;
}
if (codeSentence.Contains("to"))
{
Console.Write(2);
codeNumber[i] = 2;
}
if (codeSentence.Contains("for"))
{
Console.Write(4);
codeNumber[i] = 4;
}
}
Console.ReadKey();