Beginning of a string.... - Posted (1135 Views)
Senior Member
bobby131313
Posts: 1163
1163
Code:
If InStr(Request.ServerVariables("REMOTE_ADDR"),"41.207") > 0 Then

Is there a way I can make sure this only matches at the beginning of the string?
For example...
Match > 41.207.256.325
Do not match > 256.41.207.325

Thanks!<
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Snitz Forums Admin
ruirib
Posts: 26364
26364
If there is a match, the matching position will be returned, so you just need to check the value. If 1, it's the beginning of the string, if greater than 1 you know it wasn't matched at the beginning of the string.<
Posted
Senior Member
bobby131313
Posts: 1163
1163
Ahhhhh... So I would want...
Code:

If InStr(Request.ServerVariables("REMOTE_ADDR"),"41.207") = 1 Then

Never knew that. Thanks! bigsmile<
Posted
Snitz Forums Admin
ruirib
Posts: 26364
26364
Originally posted by bobby131313
Ahhhhh... So I would want...
Code:

If InStr(Request.ServerVariables("REMOTE_ADDR"),"41.207") = 1 Then

Never knew that. Thanks! bigsmile
Yeppers... you're welcome smile.<
Posted
Advanced Member
Carefree
Posts: 4224
4224
If InStr(Request.ServerVariables("REMOTE_ADDR"),"41.207") = 1 Then

does the same thing as

if left(Request.ServerVariables("REMOTE_ADDR",6))="41.207" then<
Posted
Senior Member
bobby131313
Posts: 1163
1163
Good to know....
So...
Code:
If InStr(Request.ServerVariables("REMOTE_ADDR"),"41.207") = 1 Then
Go the hell away! end if
and
Code:
if left(Request.ServerVariables("REMOTE_ADDR",6))="41.207" then
Go the hell away! end if
Will do the same thing.... evil
Thanks! <
Posted
Support Moderator
Doug G
Posts: 6493
6493
Using a fixed length extract will fail if your next problem visitor is from an IP like "241.207" Now it's 7 characters long. I'd use rui's solution.
<
======
Doug G
======
Computer history and help at www.dougscode.com
Posted
Advanced Member
Carefree
Posts: 4224
4224
Originally posted by Doug G
Using a fixed length extract will fail if your next problem visitor is from an IP like "241.207" Now it's 7 characters long. I'd use rui's solution.

However, since he specified he wanted "the beginning of the string", then he would not want a match of "241.207".<
 
You Must enter a message