Solved

Can Contains Property Have many items(VB2008)

Posted on 2009-05-20
5
217 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:Ahmadal_najjar2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:Ahmadal_najjar2003
ID: 24435018
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

0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 24435079
Hi Ahmad Al-najjr;

The parameter of the Contains is a simple string of one search criteria and not multiple.

You can have code as shown in the code snippet below.

Fernando
Imports System.Text.RegularExpressions
 
' Data source
Dim itm As New List(Of String)()
itm.AddRange(New String() {"File1.jpg", "File1.png", "File1.bmp", "File1.mpg", "File1.wmv", "File1.txt"})
 
' Find out if any of the strings in itm have the values jpg|png|bmp|mpg|wmv
' If any do assign those string to the list itmFound
Dim itmFound As List(Of String) = itm.FindAll(Function(f) Regex.IsMatch(f, "(jpg|png|bmp|mpg|wmv)"))
 
If itmFound.Count > 0 Then
    'some code here 
End If

Open in new window

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24435202

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

0
 

Author Closing Comment

by:Ahmadal_najjar2003
ID: 31583612
thank you
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24467412
Not a problem, glad to help.  ;=)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question