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
Solved

Can Contains Property Have many items(VB2008)

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

861 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