有人可以告诉我,我怎样才能在字典(在 VB.NET 中)中只搜索一个键的一部分?
我使用以下示例代码:
Dim PriceList As New Dictionary(Of String, Double)(System.StringComparer.OrdinalIgnoreCase)
PriceList.Add("Spaghetti alla carbonara", 21.65)
PriceList.Add("Spaghetti aglio e olio", 22.65)
PriceList.Add("Spaghetti alla napoletana", 23.65)
PriceList.Add("Spaghetti alla puttanesca ", 24.65)
PriceList.Add("Spaghetti alla gricia ", 25.65)
PriceList.Add("Spaghetti alle vongole", 26.65)
PriceList.Add("Spaghetti Bolognese", 27.65)
If PriceList.ContainsKey("spaghetti bolognese") Then
Dim price As Double = PriceList.Item("spaghetti bolognese")
Console.WriteLine("Found, price: " & price)
End If
If Not PriceList.ContainsKey("Bolognese") Then
Console.WriteLine("How can I search for only a part of a key?")
End If
如果我只知道像“Bolognese”这样的键的一部分或像“Bolo”这样的单词的一部分,我如何在完整的键中搜索这部分?