Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Like Operator

Posted on 2003-03-10
8
Medium Priority
?
1,442 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:fbk2000
8 Comments
 
LVL 10

Expert Comment

by:apollois
ID: 8107020
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
 
LVL 10

Expert Comment

by:apollois
ID: 8107040
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
 
LVL 18

Accepted Solution

by:
mgfranz earned 200 total points
ID: 8107090
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:iozturk
ID: 8107114

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
 
LVL 10

Expert Comment

by:apollois
ID: 8107280
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
 

Author Comment

by:fbk2000
ID: 8107281
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
 
LVL 10

Expert Comment

by:apollois
ID: 8107328
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
 

Author Comment

by:fbk2000
ID: 8107365
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

581 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