Link to home
Start Free TrialLog in
Avatar of Ahmadal_najjar2003
Ahmadal_najjar2003Flag for Kuwait

asked on

Can Contains Property Have many items(VB2008)

Salam

I have this code
if itm.Contains(".jpg") Or itm.Contains(".png") Or itm.Contains(".bmp") Or itm.Contains(".mpg") Or itm.Contains(".wmv")
' some code here
End If

Can contains be multible instead of using Or.

Ahmad Al-najjr
Avatar of Ahmadal_najjar2003
Ahmadal_najjar2003
Flag of Kuwait image

ASKER

I tried with my self so :

Dim MyFilesExt() As String = {".jpg", ".bmp", ".png", ".mpg", ".wmv", ".mp4", ".avi", ".mp3"}

' Now get file Extention .
                For i As Integer = 0 To MyFilesExt.Count - 1
                    If itm.Contains(MyFilesExt(i)) Then
                        ListBox1.Items.Add(itm)
                    End If
                Next

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

To add the other file types change this line of code:
 
Dim itmFound As List(Of String) = itm.FindAll(Function(f) Regex.IsMatch(f, "(jpg|png|bmp|mpg|wmv)"))
 
To this:
 
Dim itmFound As List(Of String) = itm.FindAll(Function(f) Regex.IsMatch(f, "\.(jpg|png|bmp|mpg|wmv|mp4|avi|mp3)"))

Open in new window

thank you
Not a problem, glad to help.  ;=)