Like Operator

Does the Like Operator not work in VBScript under ASP?  Something seems to not be working quite right.

Is there anything else that will offer similar functionality

I need the IsDigit, IsAlpha etc type functions that are available in C++.

I also need some sort of pattern matching.

Thanks
fbk2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

apolloisCommented:
Hi fbk2000,

VBScript has similar functions.  Check the VBScript Ref Doc:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbscripttoc.asp

Best Regards,
apollois
0
apolloisCommented:
fbk2000,
>>>Does the Like Operator not work in VBScript under ASP?

Post your code.

The only "LIKE" I know about is with SQL:

SELECT field1, field2 FROM SomeTable WHERE LName LIKE 'Smith%'


Best Regards,
apollois
0
mgfranzCommented:
VBScript has the functions;

IsArray
IsDate
IsEmpty
IsNull
IsNumeric
Is

Using "LIKE" is more or less a SQL call.  For pattern matching, look into using RegExp();

The RegExp object is used to look for and match all occurrences of a search string pattern inside a target string.
 
Each time the RegExp object finds a match during the search, a Match object is created and added to a Matches collection.
 
The search pattern is declared using the Pattern property. It could, for example, be a simple string, such as "cost analysis". However, the search pattern can also be a regular expression. Regular expressions can range from being very simple to being extremely complex. The Pattern property page contains an introductory listing of special characters that can be used with regular expressions.
 
The following code is a simpler, working version of a program published by Microsoft. Note the use of the keyword New when you create a RegExp object using Set.
 
Code:
<%
'this sub finds the matches
Sub RegExpTest(strMatchPattern, strPhrase)
    'create variables
    Dim objRegEx, Match, Matches, StrReturnStr
    'create instance of RegExp object
    Set objRegEx = New RegExp

    'find all matches
    objRegEx.Global = True
    'set case insensitive
    objRegEx.IgnoreCase = True
    'set the pattern
    objRegEx.Pattern = strMatchPattern

    'create the collection of matches
    Set Matches = objRegEx.Execute(strPhrase)

    'print out all matches
    For Each Match in Matches
        strReturnStr = "Match found at position "
        strReturnStr = strReturnStr & Match.FirstIndex & ". Match Value is '"
        strReturnStr = strReturnStr & Match.value & "'."
        'print
        Response.Write(strReturnStr & "<BR>")
    Next
End Sub

'call the subroutine
RegExpTest "is.", "Is1 is2 Is3 is4"
%>

Output:
Match found at position 0. Match Value is 'Is1'.
Match found at position 4. Match Value is 'is2'.
Match found at position 8. Match Value is 'Is3'.
Match found at position 12. Match Value is 'is4'.

 
PROPERTIES
 
Global Property
This property is only used with a RegExp object variable and returns a Boolean value. False signifies that a search should only find the first occurrence of a match. True signifies that a search should find all occurrences of a match.

Syntax: object.Global = [ True | False ]

IgnoreCase Property
This property is only used with a RegExp object variable and returns a Boolean value. False signifies that a search should be case-sensitive (i.e., upper versus lower case). True signifies that a search should ignore case in a match.

Syntax: object.IgnoreCase = [ True | False ]

Pattern Property
This property defines the regular expression or search pattern string that is to be matched during the search.

Syntax: object.Property = [ SearchPatternString ]

METHODS

Execute Method
This method is used to execute the search and to look for matches of the search pattern string (or regular expression) and the target string. Each time a match is made, a Match object is created and added to a collection that is called a Matches collection.

Syntax: object.Execute

Replace Method
This method is used to replace text found in a regular expression search. Do not confuse this method with the Replace function.

Syntax: object.Replace (String1, String2)

Test Method
This method is used to determine if the search pattern occurs within a specified string and returns a Boolean value to signify the results of the search. True is returned if the pattern is found. Otherwise, False is returned.

Syntax: object.Test
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

iozturkCommented:

Does the Like Operator not work in VBScript under ASP?
There is no. But have a look at instr it may help you.

I need the IsDigit, IsAlpha etc type functions that are available in C++.
There is no digit data type and so no need to check if a variable is digit, there are (IsNumeric, IsArray, IsDate etc.)

I also need some sort of pattern matching.
There is an object called macth and a collection of it. It supplies properties and metohd for regular expression matching.

Actually vbscript is not a full function language. You might be disappointed if you expect much.
0
apolloisCommented:
fbk2000,

Here are some more references/tutorials for ASP VBScript:

VBScript
http://www.sloppycode.net/vbscript/

VBScript Tutorial
http://www.w3schools.com/vbscript/vbscript_examples.asp

An Introduction to Regular Expression with VBScript
http://www.4guysfromrolla.com/webtech/090199-1.shtml

ASP Quick Lessons
http://www.learnasp.com/learn/index.asp

DevGuru Built-in ASP Objects Quick Reference
http://www.devguru.com/Technologies/asp/quickref/asp_intro.html



Best Regards,
apollois
0
fbk2000Author Commented:
I guess I need to clarify

Normal Visual Basic, that is, VB 6.0 has a LIKE operator
Not to be confused with the SQL LIKE Operator which I know all about.  The VB 6.0 Syntax is like this....


 Var = "1" Like "[0-9]"

 This would be the equivalent of a IsDigit Function

 Also

 Var = UCASE("H") Like "[A-Z]"

 Would be the equivalent of an IsAlpha Functino
0
apolloisCommented:
fbk2000,

>>> Var = "1" Like "[0-9]"

The is NO "Like" function in VBScript.

For pattern matching, use Regular Expressions.  You could probably write a  custom Like function using RegExp without to much trouble.

Best Regards,
apollois
0
fbk2000Author Commented:
Ok, well it's nowhere near as convenient as the normal VB syntax, but RegExp does the same thing through the .Test Method.  

mgfranz was first to suggest its use, he gets the points.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.