title: How to find a match in a list of LxWxT where Positions of L and W can vary
body: <p>I have been given the following Problem: We need to find out if a given combination of Length, Width and Thickness might have a rawmaterial on stock. 
  As Input I get the following String: </p>
  
  <blockquote>
    <p>"L:90 W:40 T:8"</p>
  </blockquote>
  
  <p>For Rawmaterials I have created a small dataclass:</p>
  
  <pre><code>Public Class RawMatInfo
  
      Private _length As String
      Private _width As String
      Private _thickness As String
  
      Public Property Length As String
          Get
              Return Me._length
          End Get
          Set(value As String)
              Me._length = value
          End Set
      End Property
  
      Public Property Width As String
          Get
              Return Me._width
          End Get
          Set(value As String)
              Me._width = value
          End Set
      End Property
  
      Public Property Thickness As String
          Get
              Return Me._thickness
          End Get
          Set(value As String)
              Me._thickness = value
          End Set
      End Property
  End Class
  </code></pre>
  
  <p>Here is some Sample raw material data:</p>
  
  <pre><code>    Dim RawMatInfo As New List(Of RawMatInfo) From {
          New RawMatInfo With {
          .Length = "0",
          .Width = "20",
          .Thickness = "3"},
          New RawMatInfo With {
          .Length = "0",
          .Width = "20",
          .Thickness = "8"},
          New RawMatInfo With {
          .Length = "0",
          .Width = "90",
          .Thickness = "8"},
          New RawMatInfo With {
          .Length = "0",
          .Width = "100",
          .Thickness = "8"},
          New RawMatInfo With {
          .Length = "0",
          .Width = "120",
          .Thickness = "8"},
          New RawMatInfo With {
          .Length = "0",
          .Width = "140",
          .Thickness = "8"},
          New RawMatInfo With {
          .Length = "260",
          .Width = "190",
          .Thickness = "3"}
          }
  </code></pre>
  
  <p>I have used 0 in length as wildcard because the raw material has theoretically infinite length. Because Length and Width are exchangable, the result for "L:90 W:40 T:8" has to be</p>
  
  <pre><code>RawMatInfo With {
          .Length = "0",
          .Width = "90",
          .Thickness = "8"}
  </code></pre>
  
  <p>So how do I get the right Rawmaterial out of the collection if one exists? I Tried several LINQ ways, but they all appeared MUCH to complicated. Here is one I tried:</p>
  
  <pre><code>Public Function GetRawMaterial(ByVal description As String) As RawMatInfo
  
      Dim tmpString = Split(description)
      Dim DescriptionDict As New Dictionary(Of String, String)
  
      For Each KVP In tmpString
          If InStr(KVP, ":") &gt; 0 Then
              Dim tmpKVP = Split(KVP, ":")
              DescriptionDict.Add(tmpKVP(0), tmpKVP(1))
          End If
      Next
  
      If DescriptionDict.ContainsKey("T") Then
          If DescriptionDict.ContainsKey("W") Then
              If DescriptionDict.ContainsKey("L") Then
  
                  Dim RawMat = RawMatInfo.Where(Function(x) x.Thickness = DescriptionDict("T"))
                  If RawMat.Count &gt; 0 Then
                      RawMat = RawMat.Where(Function(x) x.Width = DescriptionDict("W") Or x.Length = DescriptionDict("W") Or x.Length = "0")
                      If RawMat.Count &gt; 0 Then
                          RawMat = RawMat.Where(Function(x) x.Width = DescriptionDict("L") Or x.Length = DescriptionDict("L"))
                          If RawMat.Count &gt; 0 Then
                              Return RawMat
                          End If
                      End If
                  End If
              End If
          End If
      End If
  
      Return Nothing
  End Function
  </code></pre>
  
  <p>I Hope someone can help me to find an efficient way of doing this and loosen the knob in my brain</p>