Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string "starts with" another string

Tags:

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?

like image 701
Claes Gustavsson Avatar asked May 03 '12 08:05

Claes Gustavsson


People also ask

How do you check if a string starts with another string in Java?

Java String startsWith() Method The startsWith() method checks whether a string starts with the specified character(s). Tip: Use the endsWith() method to check whether a string ends with the specified character(s).

How do you check if a string starts with another string in Python?

Python String startswith() method returns True if a string starts with the specified prefix (string). If not, it returns False.

How do you check if a string starts with another string 6 14?

You can use ECMAScript 6's String. prototype. startsWith() method.

How do you check if a string starts with a letter in Python?

The startswith() string method checks whether a string starts with a particular substring. If the string starts with a specified substring, the startswith() method returns True; otherwise, the function returns False.


1 Answers

You can use the InStr() function for 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 string2 is contained in string1. You could write it as:

If positionOfMatchedString = 1 Then

to check for it beginning with.

like image 115
Jamie Dixon Avatar answered Oct 04 '22 12:10

Jamie Dixon