?
Solved

Simple string comparision in VB.NET

Posted on 2004-04-19
5
Medium Priority
?
550 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 1000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

719 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