Solved

Can Contains Property Have many items(VB2008)

Posted on 2009-05-20
5
209 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 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
System.net.Sockets Error 5 40
VB.net -  GroupBox / Panel DataBinding and behavior 3 24
Need help with a query 14 40
VB.NET System.NullReferenceException 1 27
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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

697 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