Solved

Simple string comparision in VB.NET

Posted on 2004-04-19
5
542 Views
Last Modified: 2012-06-27
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!
0
Comment
Question by:sumo_the_cat
  • 3
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 10858528
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
 
LVL 2

Author Comment

by:sumo_the_cat
ID: 10858634
InStr("helloworld, "hello", CompareMethod.Text) = 1
does it, i think..?
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 10858688
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
 
LVL 2

Author Comment

by:sumo_the_cat
ID: 10858795
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
 
LVL 2

Author Comment

by:sumo_the_cat
ID: 10858804
(points for the first suggestion!)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now