0

もう1つ目が必要です。ハッシュテーブルを正規表現でスキャンするために、このLINQ構文をいじっています。それを完全に正しく理解できないようです。目標は、すべてのキーを正規表現に一致させ、それらの結果を使用して残りの値を別の正規表現に一致させることです。以下のテスト ケースでは、最初の 3 つのエントリで終わるはずです。

Private ReadOnly Property Testhash As Hashtable
    Get
        Testhash = New Hashtable
        Testhash.Add("a1a", "abc")
        Testhash.Add("a2a", "aac")
        Testhash.Add("a3a", "acc")
        Testhash.Add("a4a", "ade")
        Testhash.Add("a1b", "abc")
        Testhash.Add("a2b", "aac")
        Testhash.Add("a3b", "acc")
        Testhash.Add("a4b", "ade")
    End Get
End Property

Public Sub TestHashSearch()

    Dim KeyPattern As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("a.a")
    Dim ValuePattern As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("a.c")

    Try
        Dim queryMatchingPairs = (From item In Testhash
                                  Let MatchedKeys = KeyPattern.Matches(item.key)
                                  From key In MatchedKeys
                                  Let MatchedValues = ValuePattern.Matches(key.value)
                                  From val In MatchedValues
                                  Select item).ToList.Distinct

        Dim info = queryMatchingPairs

    Catch ex As Exception

    End Try

End Sub
4

2 に答える 2

0

もっと早く休んで、もう少し頑張ればよかった。正しい解決策は、2 番目の正規表現で下位の「キーから」ではなく、元の「アイテムから」を使用することです。また、ハッシュテーブルには「distinct」は不要です。

            Dim queryMatchingPairs = (From item In Testhash
                                      Let MatchedKeys = KeyPattern.Matches(item.key)
                                      From key In MatchedKeys
                                      Let MatchedValues = ValuePattern.Matches(item.value)
                                      From val In MatchedValues
                                      Select item).ToList
于 2013-08-06T13:15:47.270 に答える