There is no built-in method that I know of.
But for this you can iterate over all options and for each count IndexOf . Then extract a minimum that is not -1 (from "not found"):
int position = options.Select(o => "01234".IndexOf(o)) .OrderBy(i =>i).FirstOrDefault(i=> i != -1);
Or instead of sorting (which is O(nlogn) ), find the minimum ( O(n) ):
int position = options.Select(o => "01234".IndexOf(o)) .Where(i => i != -1).DefaultIfEmpty(-1).Min();
As for editing, you can consider building and an array of suffix trees - the array contains m elements, where m is the individual sum of the first letters of your options words. As a general example:
if the parameters are "some", "word", "something", "other" , then you built:
0 1 2... +-----------------------+ | s | w | o | +- | ------ | ------ | -+ oot | | | mrh | | | ede / \ | | $ tr $ | | ... $
Then you repeat your line and for each letter you check to see if it is in an array. If not continue further. If so, you can go deeper into the nested tree and check the next letter of the string compared to the next level in the tree. If at the end of the main line you have not reached any of $ , then there is no options element in the text. Of course, you can have an array like HashSet<T> to improve the search for the first letter of the word.
source share