469,268 Members | 942 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

Variable Contains question

Hi,

I have a variable in an app called GenericTitle which contains text, a
persons job title funnily enough.

I want to check whether this variable contains the word "director" and if it
does, then redirect to another page for example.

Can somebody post some code that would let me check this?

Your help is much appreciated.
Jul 19 '05 #1
15 7389
<%

If CheckIt(stringtocheck) = True Then
Response.Redirect "itsthere.asp"
Else
Response.Write "it's not there"
End If

Function CheckIt(strString)
If Instr(String, "director") Then
CheckIt = True
Else
CheckIt = False
End Function
End Function

%>

Or simply;

<%
If Instr(StringToCheck, "director") Then
Response.Write "it's there"
Else
Response.Write "it's not there"
End If
%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Miguel Orrego <mi****@stressedmonkey.net-nospam> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi,

I have a variable in an app called GenericTitle which contains text, a
persons job title funnily enough.

I want to check whether this variable contains the word "director" and if it does, then redirect to another page for example.

Can somebody post some code that would let me check this?

Your help is much appreciated.

Jul 19 '05 #2
Hi Steve,

Thanks for your reply, however that only seems to work if the string
contains only the word director, if for example it contains "senior
director" it doesn't work.

How can I amend that so that if it contains the word director, irrespective
of what else is there, it returns true?

Thanks again.
"Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
<%

If CheckIt(stringtocheck) = True Then
Response.Redirect "itsthere.asp"
Else
Response.Write "it's not there"
End If

Function CheckIt(strString)
If Instr(String, "director") Then
CheckIt = True
Else
CheckIt = False
End Function
End Function

%>

Or simply;

<%
If Instr(StringToCheck, "director") Then
Response.Write "it's there"
Else
Response.Write "it's not there"
End If
%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Miguel Orrego <mi****@stressedmonkey.net-nospam> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi,

I have a variable in an app called GenericTitle which contains text, a
persons job title funnily enough.

I want to check whether this variable contains the word "director" and
if it
does, then redirect to another page for example.

Can somebody post some code that would let me check this?

Your help is much appreciated.


Jul 19 '05 #3
It shouldn't be doing that..... but, you can always modify;

If Instr(String, "director") Then

to

If Instr(String, " director") Then

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Miguel Orrego <mi****@stressedmonkey.net-nospam> wrote in message
news:40**********************@news.dial.pipex.com. ..
Hi Steve,

Thanks for your reply, however that only seems to work if the string
contains only the word director, if for example it contains "senior
director" it doesn't work.

How can I amend that so that if it contains the word director, irrespective of what else is there, it returns true?

Thanks again.
"Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
<%

If CheckIt(stringtocheck) = True Then
Response.Redirect "itsthere.asp"
Else
Response.Write "it's not there"
End If

Function CheckIt(strString)
If Instr(String, "director") Then
CheckIt = True
Else
CheckIt = False
End Function
End Function

%>

Or simply;

<%
If Instr(StringToCheck, "director") Then
Response.Write "it's there"
Else
Response.Write "it's not there"
End If
%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Miguel Orrego <mi****@stressedmonkey.net-nospam> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi,

I have a variable in an app called GenericTitle which contains text, a
persons job title funnily enough.

I want to check whether this variable contains the word "director" and

if
it
does, then redirect to another page for example.

Can somebody post some code that would let me check this?

Your help is much appreciated.



Jul 19 '05 #4
"Miguel Orrego" wrote:
: I have a variable in an app called GenericTitle which contains text, a
: persons job title funnily enough.
:
: I want to check whether this variable contains the word "director" and if
it
: does, then redirect to another page for example.
:
: Can somebody post some code that would let me check this?

with regular expressions

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True

sub getTitle(strTitle, go, goelse)
Dim re, str, em
str = "director"
Set re = new RegExp
With re
.Pattern = "(\w)+"
.IgnoreCase = True
.Global = false
End With
Set em = re.Execute(strTitle)
if lcase(em(0)) = "director" then
Response.Redirect(go) ' director
else
Response.Redirect(goelse) ' not director
end if
set re = nothing
end sub

dim GenericTitle
GenericTitle = Request.QueryString("gt")
getTitle "" & GenericTitle & "", "http://wallstreet.com/",
"http://disney.com"
%>

You can test it here:
http://kiddanger.com/lab/regexp1.asp?gt=director
http://kiddanger.com/lab/regexp1.asp?gt=janitor

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #5
Nice job on the coding...but since some folks do their news'ing at work I
personally wouldn't have redirected to a site (wallstreet.com) with gambling
on it. I worked at an organization a few years back that tracked every move
I made on the internet, and that site would have earned me a reprimand.

Just food for thought.

--
William Morris
Product Development, Seritas LLC
Kansas City, Missouri

"Roland Hall" <nobody@nowhere> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl...
"Miguel Orrego" wrote:
: I have a variable in an app called GenericTitle which contains text, a
: persons job title funnily enough.
:
: I want to check whether this variable contains the word "director" and if it
: does, then redirect to another page for example.
:
: Can somebody post some code that would let me check this?

with regular expressions

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True

sub getTitle(strTitle, go, goelse)
Dim re, str, em
str = "director"
Set re = new RegExp
With re
.Pattern = "(\w)+"
.IgnoreCase = True
.Global = false
End With
Set em = re.Execute(strTitle)
if lcase(em(0)) = "director" then
Response.Redirect(go) ' director
else
Response.Redirect(goelse) ' not director
end if
set re = nothing
end sub

dim GenericTitle
GenericTitle = Request.QueryString("gt")
getTitle "" & GenericTitle & "", "http://wallstreet.com/",
"http://disney.com"
%>

You can test it here:
http://kiddanger.com/lab/regexp1.asp?gt=director
http://kiddanger.com/lab/regexp1.asp?gt=janitor

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp MSDN Library - http://msdn.microsoft.com/library/default.asp

Jul 19 '05 #6
That's not true. What you are probably running into is a case sensitivity
problem. Change Steven's code to:

Function CheckIt(pString)
If Instr(lcase(pString), "director") Then
CheckIt = True
Else
CheckIt = False
End if
End Function

HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From header is
my spam trap, so I don't check it very often. You will get a quicker
response by posting to the newsgroup.

"Miguel Orrego" <mi****@stressedmonkey.net-nospam> wrote in message
news:40**********************@news.dial.pipex.com. ..
Hi Steve,

Thanks for your reply, however that only seems to work if the string
contains only the word director, if for example it contains "senior
director" it doesn't work.

How can I amend that so that if it contains the word director, irrespective of what else is there, it returns true?

Thanks again.
"Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
<%

If CheckIt(stringtocheck) = True Then
Response.Redirect "itsthere.asp"
Else
Response.Write "it's not there"
End If

Function CheckIt(strString)
If Instr(String, "director") Then
CheckIt = True
Else
CheckIt = False
End Function
End Function

%>

Or simply;

<%
If Instr(StringToCheck, "director") Then
Response.Write "it's there"
Else
Response.Write "it's not there"
End If
%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Miguel Orrego <mi****@stressedmonkey.net-nospam> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi,

I have a variable in an app called GenericTitle which contains text, a
persons job title funnily enough.

I want to check whether this variable contains the word "director" and

if
it
does, then redirect to another page for example.

Can somebody post some code that would let me check this?

Your help is much appreciated.



Jul 19 '05 #7
Bob Barrows [MVP] wrote on 12 feb 2004 in
microsoft.public.inetserver.asp.general:
Function CheckIt(pString)
If Instr(lcase(pString), "director") Then
CheckIt = True
Else
CheckIt = False
End if
End Function


Function CheckIt(pString)
CheckIt = Instr(lcase(pString), "director")>0
End Function
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #8
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Change Steven's code to:

If Instr(lcase(pString), "director") Then


Or, perhaps even better...

If Instr( 1, pString, "director", 1 ) > 0 Then

HTH,
Phill W.
Jul 19 '05 #9
Thanks for the help guys, I've got it working fine now, except for some
people in my org don't have Directors, so I now need to change it to check
for director or vp or senior manager.

What would the syntax be in the function for it to check for more than one
word? :

Function CheckIt(pString)
If Instr(lcase(pString), "director") Then
CheckIt = True
Else
CheckIt = False
End if
End Function

Thanks again all.
"Miguel Orrego" <mi****@stressedmonkey.net-nospam> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi,

I have a variable in an app called GenericTitle which contains text, a
persons job title funnily enough.

I want to check whether this variable contains the word "director" and if it does, then redirect to another page for example.

Can somebody post some code that would let me check this?

Your help is much appreciated.

Jul 19 '05 #10
e.g. If CheckIt(SomeData, "director") Then
'........true
Else
'......false
End if

Function CheckIt(pString, StringToFind)
If Instr(lcase(pString), StringToFind) Then
CheckIt = True
Else
CheckIt = False
End if
End Function
--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Miguel Orrego <mi****@stressedmonkey.net-nospam> wrote in message
news:40***********************@news.dial.pipex.com ...
Thanks for the help guys, I've got it working fine now, except for some
people in my org don't have Directors, so I now need to change it to check
for director or vp or senior manager.

What would the syntax be in the function for it to check for more than one
word? :

Function CheckIt(pString)
If Instr(lcase(pString), "director") Then
CheckIt = True
Else
CheckIt = False
End if
End Function

Thanks again all.
"Miguel Orrego" <mi****@stressedmonkey.net-nospam> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi,

I have a variable in an app called GenericTitle which contains text, a
persons job title funnily enough.

I want to check whether this variable contains the word "director" and
if it
does, then redirect to another page for example.

Can somebody post some code that would let me check this?

Your help is much appreciated.


Jul 19 '05 #11

"Roland Hall" <nobody@nowhere> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl...
"Miguel Orrego" wrote:
: I have a variable in an app called GenericTitle which contains text, a : persons job title funnily enough.
:
: I want to check whether this variable contains the word "director" and if it
: does, then redirect to another page for example.
:
: Can somebody post some code that would let me check this?

with regular expressions

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True

sub getTitle(strTitle, go, goelse)
Dim re, str, em
str = "director"
Set re = new RegExp
With re
.Pattern = "(\w)+"
.IgnoreCase = True
.Global = false
End With
Set em = re.Execute(strTitle)
if lcase(em(0)) = "director" then
Response.Redirect(go) ' director
else
Response.Redirect(goelse) ' not director
end if
set re = nothing
end sub

dim GenericTitle
GenericTitle = Request.QueryString("gt")
getTitle "" & GenericTitle & "", "http://wallstreet.com/",
"http://disney.com"
%>


The above code only works when the title begins with the word
"director". Here are some false negatives that your code does not
capture:

assistant director
assistant_director
director_of_photography
directory

Here's an alternative function:
<%
Function IsDirector(str)
Dim re,retVal
Set re = New RegExp
With re
.Global = True
.IgnoreCase = True
.Pattern = "director"
retVal = .Test(str)
End With
Set re = Nothing
IsDirector = retVal
End Function
%>

Also note that from a performance standpoint, it can be inefficient to
instantiate a RegExp object if it's only going to be used once. The
merits of regular expression objects lie in their robust pattern
matching capabilities and the economies of scale that come into play
when the strings being matches are many or large.

HTH
-Chris Hohmann
Jul 19 '05 #12
"William Morris" wrote:
: Nice job on the coding...but since some folks do their news'ing at work I
: personally wouldn't have redirected to a site (wallstreet.com) with
gambling
: on it. I worked at an organization a few years back that tracked every
move
: I made on the internet, and that site would have earned me a reprimand.
:
: Just food for thought.

You're right William. I didn't consider that.
Thank you.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #13
"Chris Hohmann" wrote:
: "Roland Hall" wrote:
: > "Miguel Orrego" wrote:
: > : I have a variable in an app called GenericTitle which contains text,
: a
: > : persons job title funnily enough.
: > :
: > : I want to check whether this variable contains the word "director"
: and if
: > it
: > : does, then redirect to another page for example.
: > :
: > : Can somebody post some code that would let me check this?
: >
: > with regular expressions
: >
: > <%@ Language=VBScript %>
: > <%
: > Option Explicit
: > Response.Buffer = True
: >
: > sub getTitle(strTitle, go, goelse)
: > Dim re, str, em
: > str = "director"
: > Set re = new RegExp
: > With re
: > .Pattern = "(\w)+"
: > .IgnoreCase = True
: > .Global = false
: > End With
: > Set em = re.Execute(strTitle)
: > if lcase(em(0)) = "director" then
: > Response.Redirect(go) ' director
: > else
: > Response.Redirect(goelse) ' not director
: > end if
: > set re = nothing
: > end sub
: >
: > dim GenericTitle
: > GenericTitle = Request.QueryString("gt")
: > getTitle "" & GenericTitle & "", "http://wallstreet.com/",
: > "http://disney.com"
: > %>
:
: The above code only works when the title begins with the word
: "director". Here are some false negatives that your code does not
: capture:
:
: assistant director
: assistant_director
: director_of_photography
: directory
:
: Here's an alternative function:
: <%
: Function IsDirector(str)
: Dim re,retVal
: Set re = New RegExp
: With re
: .Global = True
: .IgnoreCase = True
: .Pattern = "director"
: retVal = .Test(str)
: End With
: Set re = Nothing
: IsDirector = retVal
: End Function
: %>
:
: Also note that from a performance standpoint, it can be inefficient to
: instantiate a RegExp object if it's only going to be used once. The
: merits of regular expression objects lie in their robust pattern
: matching capabilities and the economies of scale that come into play
: when the strings being matches are many or large.

I missed the word contains in the OPs post, I thought it was equal.

Are you telling me the regular expression has a lot of overhead and should
only be considered when it is a global search?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #14
"Roland Hall" <nobody@nowhere> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
"Chris Hohmann" wrote:
: Also note that from a performance standpoint, it can be inefficient to : instantiate a RegExp object if it's only going to be used once. The
: merits of regular expression objects lie in their robust pattern
: matching capabilities and the economies of scale that come into play
: when the strings being matches are many or large.

I missed the word contains in the OPs post, I thought it was equal.

Are you telling me the regular expression has a lot of overhead and should only be considered when it is a global search?


"A lot of overhead" is subjective. I will say that RegExp objects incur
overhead that calls to native string functions like InStr do not. Is
"global search" a reference to the RegExp.Global property? If so, the
property does not necessarily have an effect on the performance of a
regular expression. For instance an enormous string could have a
singular match at the very end of the string. RegExp should be
considered in the following circumstances:

1. The pattern matching requires would be difficult/impossible to
achieve using built-in string functions
2. The string to be search is large, i.e.. the contents of a file.

Of course, each circumstance will vary and the only definitive way to
insure that the right method is being employed is to test each approach.

HTH
-Chris Hohmann
Jul 19 '05 #15
"Chris Hohmann" wrote:
: "Roland Hall" wrote:
: > Are you telling me the regular expression has a lot of overhead and
: should
: > only be considered when it is a global search?
:
: "A lot of overhead" is subjective. I will say that RegExp objects incur
: overhead that calls to native string functions like InStr do not. Is
: "global search" a reference to the RegExp.Global property? If so, the
: property does not necessarily have an effect on the performance of a
: regular expression. For instance an enormous string could have a
: singular match at the very end of the string. RegExp should be
: considered in the following circumstances:
:
: 1. The pattern matching requires would be difficult/impossible to
: achieve using built-in string functions
: 2. The string to be search is large, i.e.. the contents of a file.
:
: Of course, each circumstance will vary and the only definitive way to
: insure that the right method is being employed is to test each approach.

I have seen it used so widely for small tasks that do not apply to the above
and I never tested the performance of it with other methods. Thanks for the
info Chris.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by arcticool | last post: by
2 posts views Thread by Bit byte | last post: by
reply views Thread by ajay.kalyan | last post: by
1 post views Thread by Mark Huebner | last post: by
2 posts views Thread by mattdaddym | last post: by
reply views Thread by mosesdinakaran | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.