• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 824
  • Last Modified:

Vb.NET see if list of string not contains "/"

Hi, I have a list(of String) with some elements in it.

I need to know if that list contains("/") at least 1 element and ALSO  NOT contains("/") at least one element then return lets say True

in other words... lets say my list is:

Test
Hello
Hi / Earth
George

I have both, (not with "/"  and with "/")

so I would return True


if list is:

Hi / Hello
Earth /  Sky
Thank / You / Very Much

then I would return False because there is only elements with "/"


can you help ?
0
PhilippeRenaud
Asked:
PhilippeRenaud
  • 2
2 Solutions
 
Paul MacDonaldDirector, Information SystemsCommented:
This is one way.  It's probably not the most efficient or fastest:

          Dim lstList As List(Of String)
          Dim blnSlash As Boolean = False
          Dim blnNoSlash As Boolean = False

          For Each strItem As String In lstList
            If strItem.Contains("/") Then
              blnSlash = True
            Else
              blnNoSlash = True
            End If
          Next

          If blnSlash And blnNoSlash Then
          ...do something...
          End If
0
 
PhilippeRenaudAuthor Commented:
yea,  ill give points for that, is there a way maybe also for one line with linq maybe ?

ill just wait for my own knowledge but I accept this.
0
 
CodeCruiserCommented:
You can use either the Find method or the Contains<predicate> method

If list.Contains(function(x) x.contains("\")) AND list.Contains(function(x) Not X.contains("\"))
0
 
PhilippeRenaudAuthor Commented:
thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now