Last post Apr 20, 2008 04:56 AM by polynaux
Apr 19, 2008 07:42 AM|polynaux|LINK
I am creating a list and add x elements.
Dim ListOfAlternativesSet As New Generic.List(Of String)
Dim i As Integer = 0
For Each AddListWithMembershipRow As GridViewRow In GridViewAlt.Rows
ListOfAlternativesSet.Add(AddListWithMembershipRow.Cells(3).Text + " _" + AddListWithMembershipRow.Cells(4).Text)
i = i + 1
If ListOfAlternativesSet.Contains(TotalTemperature) Then xxxx
Which results in "False". But it should be true because the List does contain TotalTemperature (the first part of my string
I think I need to re-write the If statement like this:
(YourString.Length - 3,3)
If Substring(ListOfAlternativesSet.Contains(AddListWithMembershipRow.Cells(3).Text +" _").Length -3,3) Then xxxx
In case that possible, what would be the correct syntax? Or is there another way for checking of the generic.list contains parts of "TotalTemperature _100" ?
PS: I can not seperate the strings (need them together at a later stage)
Apr 19, 2008 05:30 PM|mbanavige|LINK
when you check the list with .Contains, it's looking for an exact match on each item - not a partial match.
to check your list to see if any of its items might be a partial match, you could enumerate the list (for/each) and do a substring check on each item.
Apr 20, 2008 04:56 AM|polynaux|LINK
that was not the answer I was hoping for :-/
I am using the list.contains method in about 30 different if statements and it would be a pain to write 30+ loops just to see if there is a partial matching.
I wonder if this would work:
If ListOfAlternatviesSet.FindAll(Temperature EndsWithSaurus) = True Then xx
ElseResult=FalseEnd If Private Shared Function EndsWithSaurus(ByVal s As String) _ As Boolean
' AndAlso prevents evaluation of the second Boolean ' expression if the string is so short that an error ' would occur.
If (s.Length > 5) AndAlso _ (s.Substring(s.Length - 6).ToLower() = "saurus") Then Return True Else Return False End If End Function
Otherwise It seems I have to think about a new solution to the problem.