Solved

Can Contains Property Have many items(VB2008)

Posted on 2009-05-20
5
180 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
  • 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 62

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 62

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 62

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now