Solved

Simple string comparision in VB.NET

Posted on 2004-04-19
5
544 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

813 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

16 Experts available now in Live!

Get 1:1 Help Now