Solved

Simple string comparision in VB.NET

Posted on 2004-04-19
5
547 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help converting bitmap to image in VB.Net 8 70
orderby list (from Json) 1 46
Help with Report Viewer in VS2013 6 34
How do I "share" on social sites? 2 40
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 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