Make sure the line "starts with" another line in classic ASP?

I want to check if the address starts with http://www.youtube.com in asp.

If I have something like this

if rs("mainVideoName")="http://www.youtube.com*" then 

This does not work, so how can I do this?

Thanks!

+8
asp-classic
source share
3 answers

Try the following:

  Function UrlStartsWith(string1, string2) UrlStartsWith = InStr(1, string1, string2, 1) = 1 End Function If UrlStartsWith(rs("mainVideoName"), "http://www.youtube.com") Then End If 

Starting with is checked using IntStr and ensuring that it returns 1 as the starting position at which the search string is found. Since you are testing the URL, the code above uses TextCompare to provide case insensitivity.

+10
source share

You can use the InStr() function to do this:

 Dim positionOfMatchedString positionOfMatchedString= InStr(rs("mainVideoName"),"http://www.youtube.com") If positionOfMatchedString > 0 Then // Do your stuff here End If 

As Anthony points out, this tells you that line2 is contained in line1. You could write this as:

 If positionOfMatchedString = 1 Then 

to check it starting at.

+2
source share

What about...

 Dim s: s = "http://www.youtube.com" Dim l: l = Len(s) If Left(rs("mainVideoName"), l) = s Then ' String begins with URL part ' End If 
+1
source share

All Articles