Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

array with regular expression to compare againts a variable

Posted on 2008-06-16
5
Medium Priority
?
386 Views
Last Modified: 2008-06-17
I need help with a vbScript application I am working on...I want to find the best way I can create an array and used to check if my variable contains any of the elements in the array.

I just want to check if the variable contains any of the following characters:
( ) _   - + ? ¿

 
0
Comment
Question by:a0k0a7
[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
5 Comments
 
LVL 3

Assisted Solution

by:nds_rahulmistry
nds_rahulmistry earned 800 total points
ID: 21800412

YOU CAN USE FOLLOWING CODE TO CHECK THIS

RAHUL


dim strTmp
dim arr(8)
 
strTmp = "My Name Is (Rahul)"	'YOUR VARIABLE TO BE CHECKED
 
arr(0) = "("
arr(1) = ")"
arr(2) = "_"
arr(3) = " "
arr(4) = "-"
arr(5) = "+"
arr(6) = "?"
arr(7) = "¿"
 
for i=0 to 7
	if instr(1, strTmp, arr(i)) > 0 then
		'VARIABLE CONTAINS THE SPECIAL CHARACTER
		'YOUR CODE TO HANDLE THIS WILL GO HERE
		MsgBox "Found"
		exit for
	else
		'VARIABLE DOES NOT CONTAINS THE SPECIAL CHARACTER
		'YOUR CODE TO HANDLE THIS WILL GO HERE
		'MsgBox "Not Found"
	End If
next

Open in new window

0
 
LVL 6

Accepted Solution

by:
psychic_zero earned 1200 total points
ID: 21800442
Pls try this code:
Dim spchar
 
spchar = Array("(", ")", "_", " ", "-", "+", "?", "")
 
myvar = "abd?"   'your variable
 
For i = 0 To UBound(spchar)
    result = InStr(myvar, spchar(i))
    If result <> 0 Then
        document.write ("Special character found")
        Exit For
    End If
Next

Open in new window

0
 
LVL 8

Author Comment

by:a0k0a7
ID: 21800451
is there's way I can hold all the characters to look for in a single array...

myArray =  {"(", ")", "_", "&nbsp;" }

0
 
LVL 8

Author Comment

by:a0k0a7
ID: 21800453
thx psychic_zero, i will try that one
0
 
LVL 8

Author Comment

by:a0k0a7
ID: 21800620
nds_rahulmistry, psychic_zero... thanks for your help
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

688 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