I have word(s) with one or more prefixes (starting letters) and a list of predefined prefixes. I want to count the number of prefixes attached to the given word. My Code:
public static void main(string[] args)
{
List<string> prefixes=new List<string>();
prefixes.Add("im");
prefixes.Add("anti");
prefixes.Add("auto");
prefixes.Add("dis");
Console.Write(PrefixesCount("autoDiscount",prefixes));
}
public static int PrefixesCount(string word,List<string> prefixes)
{
return (from t in prefixes where word.StartWith(t) select t).ToList<string>().Count;
}
output: 1
It should return "2" as "auto" and "dis" are prefixes.