Q:

Search for a word in a given string of words

I have a string of words that the user can input and I need to search for a specific word in the order given below and take action based on word selected.

Join, Yes
Stop,
Cancel
Help
Account
Card

For example if the User inputs the command Card Stop as the input then I should first process the word Stop instead of Card. Similarly if the user inputs Join Frank then I should process the word Join. Similarly if user inputs Stop Help then I should process Stop. 
How do I go about doing that?
EDIT: 
I tried the following but in which case the set of valid words that needs to be searched is put in an Enum and I loop through the split text. But in this case if the user input the word as "Card Stop" then since it one of the correct command in the Enum it simply sends the response of Card and skips the rest. What I would ideally like is it should process Stop instead Card. basically follow the above priority. 
Is that possible?  
var Tokens = Regex.Split(userText, @"\s+"); 

            foreach (string stringText in Tokens)
            {
                if (Enum.IsDefined(typeof(TextType), stringText))
                {
                    textType = (TextType)Enum.Parse(typeof(TextType), stringText, true);
                    if ((isTextTypeJoin(textType)))
                    {
                        return textType;
                    }
                }
            }

A:

In response to your edit, you need to flip it so you loop through the enum, not through the input:
foreach(var entry in Enum.GetNames(typeof(TextType)))
{
    if (Regex.IsMatch(input, string.Format(@"\b{0}\b", Regex.Escape(entry))))
    {
        return entry;
    }
}

return TextType.SomeDefaultValue;

Where input is your user-input string. This loops through the enum values and returns the first one that's found in the string.

