Check if string “starts with” another string

vbscript

I want to check if an address starts with http://www.youtube.com.

If I have something like this

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

This doesn't work, so how can I do it?

Best Answer

Try this:

 Function UrlStartsWith(string1, string2)
     UrlStartsWith = InStr(1, string1, string2, 1) = 1
 End Function

 If UrlStartsWith(rs("mainVideoName"), "http://www.youtube.com") Then


 End If

Starts with is tested by using IntStr and ensuring that it returns 1 as the starting position that the search string is found. Since you are testing a URL the code above uses a TextCompare to make insensitive to case.

Related Topic