There is not a way of going "A thru E" in code, you will need to make a list or array of strings that represent the starting letters you want to check.
Take a look at the following example solution:
I've created the WordForm objects in-code; obviously yours come from your DB and you can do what you need with them.
The .StartsWith("whatever")
Linq extension method is a nice comparison instead of using the .Substring(0,7) == "whatever"
.
public static void Main()
{
var words = new List<WordForm>();
words.Add(new WordForm { WordId = "Apple" });
words.Add(new WordForm { WordId = "Banana" });
words.Add(new WordForm { WordId = "Cake" });
words.Add(new WordForm { WordId = "Date" });
words.Add(new WordForm { WordId = "Egg" });
var filterChars = new string[] { "C", "D" };
var filtered = GetStartingWith(filterChars, words);
foreach (var item in filtered)
{
Console.WriteLine(item.WordId);
}
}
public static List<WordForm> GetStartingWith(string[] startingLetters, List<WordForm> collection)
{
var returnList = new List<WordForm>();
foreach (var wordForm in collection)
{
foreach (var startingLetter in startingLetters)
{
if (wordForm.WordId.StartsWith(startingLetter))
{
returnList.Add(wordForm);
}
}
}
return returnList;
}
public class WordForm
{
public string WordId { get; set; }
//... Plus all your other properties on WordForm...
}
This returns me
"Cake" and "Date" in console.
What the above does:
Give the method a list of letters to check against: in this case A, B, C, D, E; and the list to check in (your List<WordForm>
collection)
It then loops through the WordForm objects and checks if it starts with any of the startingLetters you've given it.
If it matches a starting letter e.g. "Cake".StartsWith("C")
(Cake starts with "C"), then add it to a list that will then be returned with the filtered objects in.