[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Can Contains Property Have many items(VB2008)

Posted on 2009-05-20
5
Medium Priority
?
225 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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

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 64

Expert Comment

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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

649 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