Beginning of a string.... - Postet den (1137 Views)
Senior Member
bobby131313
Innlegg: 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!<
   
 Sidestørrelse 
Postet den
Snitz Forums Admin
ruirib
Innlegg: 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.<
Postet den
Senior Member
bobby131313
Innlegg: 1163
1163
Ahhhhh... So I would want...
Code:

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

Never knew that. Thanks! bigsmile<
Postet den
Snitz Forums Admin
ruirib
Innlegg: 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.<
Postet den
Advanced Member
Carefree
Innlegg: 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<
Postet den
Senior Member
bobby131313
Innlegg: 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! <
Postet den
Support Moderator
Doug G
Innlegg: 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
Postet den
Advanced Member
Carefree
Innlegg: 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".<
 
Du må legge inn en melding