我想检查地址是否以asp中的http://www.youtube.com开头.
如果我有这样的事情
if rs("mainVideoName")="http://www.youtube.com*" then
Run Code Online (Sandbox Code Playgroud)
这不起作用,我怎么能这样做?
谢谢!
Ant*_*nes 12
试试这个:
Function UrlStartsWith(string1, string2)
UrlStartsWith = InStr(1, string1, string2, 1) = 1
End Function
If UrlStartsWith(rs("mainVideoName"), "http://www.youtube.com") Then
End If
Run Code Online (Sandbox Code Playgroud)
开始时通过使用IntStr
并确保它返回1作为找到搜索字符串的起始位置进行测试.由于您正在测试URL,因此上面的代码使用TextCompare对case进行不敏感.
您可以使用该InStr()
函数来实现此目的:
Dim positionOfMatchedString
positionOfMatchedString= InStr(rs("mainVideoName"),"http://www.youtube.com")
If positionOfMatchedString > 0 Then
// Do your stuff here
End If
Run Code Online (Sandbox Code Playgroud)
正如 Anthony 指出的,这告诉您 string2 包含在string1 中。你可以把它写成:
If positionOfMatchedString = 1 Then
Run Code Online (Sandbox Code Playgroud)
检查它是否以开头。