Simple string comparision in VB.NET

Hi,
How do you say

"if string1 starts with string2 then..."

in VB.NET?

E.g.
string1 = "helloworld", sting2 = "hello" ----- TRUE
string1 = "helloworld", string2 = "yhelloworld" ----- FALSE

Thanks!
LVL 2
sumo_the_catAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
TimCotteeConnect With a Mentor Commented:
Hi sumo_the_cat,

Could use:

If Left(String1,Len(String2)) = String2 Then

Or perhaps

If String1 Like String2 & "*" Then

Tim Cottee
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
sumo_the_catAuthor Commented:
InStr("helloworld, "hello", CompareMethod.Text) = 1
does it, i think..?
0
 
TimCotteeCommented:
sumo_the_cat,

That works too, just shows that there is more than one way to skin a cat, even a sumo cat!

Tim.
0
 
sumo_the_catAuthor Commented:
That seems to be the problem with this coding lark:- you spend ages working out how to do something, but you spend much longer working out the best way to do it..!

Thanks,
Peter.
0
 
sumo_the_catAuthor Commented:
(points for the first suggestion!)
0
All Courses

From novice to tech pro — start learning today.