[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Like Operator

Posted on 2003-03-10
8
Medium Priority
?
1,439 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
[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
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
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!

 
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

649 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