Home All Groups Group Topic Archive Search About

get first 50 characters

Author
23 Jun 2006 12:39 PM
John
I have a string that is 100 characters long, I need to get the first 50, How
can I do that in VB?
I haven't coded in VB in years and I forget the syntax for it.

Author
23 Jun 2006 12:45 PM
Terry Olsen
ShortString = LongString.SubString(0,50)


Show quoteHide quote
"John" <CSharp***@gmail.com> wrote in message
news:O4JATIslGHA.3588@TK2MSFTNGP02.phx.gbl...
>I have a string that is 100 characters long, I need to get the first 50,
>How can I do that in VB?
> I haven't coded in VB in years and I forget the syntax for it.
>
>
>
>
Author
23 Jun 2006 4:02 PM
crferguson@gmail.com
There are a few different ways you can try:

Mid(strString, 1, 50)
Strings.Left(strString, 50)

are a couple...

Cory

John wrote:
Show quoteHide quote
> I have a string that is 100 characters long, I need to get the first 50, How
> can I do that in VB?
> I haven't coded in VB in years and I forget the syntax for it.
Author
23 Jun 2006 5:08 PM
Herfried K. Wagner [MVP]
"John" <CSharp***@gmail.com> schrieb:
>I have a string that is 100 characters long, I need to get the first 50,
>How can I do that in VB?
> I haven't coded in VB in years and I forget the syntax for it.

I prefer 'Left(str, 50)'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
23 Jun 2006 5:12 PM
Stuart Nathan
Terry Olsen is the standard VB.net way
Author
23 Jun 2006 6:07 PM
Herfried K. Wagner [MVP]
"Stuart Nathan" <stuart.nat***@homecall.co.uk> schrieb:
> Terry Olsen is the standard VB.net way

It's the standard low-level .NET Framework way, but 'Left' is the standard
VB.NET way.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
23 Jun 2006 6:23 PM
Cor Ligthert [MVP]
>
> It's the standard low-level .NET Framework way, but 'Left' is the standard
> VB.NET way.
>
Than why did the left in Substring,

I think it is just a matter a preference. I use Substring, I never can think
anymore with an indexer starting at 1.

You are right if you say that Left is the VB way which is in all VB
languages. But that does not make it for me the a "standard".

Cor
Author
23 Jun 2006 7:05 PM
Herfried K. Wagner [MVP]
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
>> It's the standard low-level .NET Framework way, but 'Left' is the
>> standard VB.NET way.
>>
> Than why did the left in Substring,
>
> I think it is just a matter a preference. I use Substring, I never can
> think anymore with an indexer starting at 1.

'Left' doesn't need any start index.  That's one of its big advantages over
'Substring'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
24 Jun 2006 12:51 AM
Dennis
Another advantage of Left is that if there isn't 50 characters, it will
return all the characters or "" if there is no characters...Substring throws
an exception so if you are willing to allow less than 50 characters, you have
to continually check the string length or be prepared to get a runtime
exception.

--
Dennis in Houston


Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
> >> It's the standard low-level .NET Framework way, but 'Left' is the
> >> standard VB.NET way.
> >>
> > Than why did the left in Substring,
> >
> > I think it is just a matter a preference. I use Substring, I never can
> > think anymore with an indexer starting at 1.
>
> 'Left' doesn't need any start index.  That's one of its big advantages over
> 'Substring'.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>
Author
24 Jun 2006 4:59 AM
Cor Ligthert [MVP]
Dennis,

That I agree, (I would not write it, but it has some advantages) however I
don't use it, and I won't call it "the" standard. There are no "standards"
in VBNet, that is one of the things why I like it.

Cor

Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> schreef in bericht
news:A6D2CDE7-B8E9-4134-9711-CC7D6E0080EB@microsoft.com...
> Another advantage of Left is that if there isn't 50 characters, it will
> return all the characters or "" if there is no characters...Substring
> throws
> an exception so if you are willing to allow less than 50 characters, you
> have
> to continually check the string length or be prepared to get a runtime
> exception.
>
> --
> Dennis in Houston
>
>
> "Herfried K. Wagner [MVP]" wrote:
>
>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
>> >> It's the standard low-level .NET Framework way, but 'Left' is the
>> >> standard VB.NET way.
>> >>
>> > Than why did the left in Substring,
>> >
>> > I think it is just a matter a preference. I use Substring, I never can
>> > think anymore with an indexer starting at 1.
>>
>> 'Left' doesn't need any start index.  That's one of its big advantages
>> over
>> 'Substring'.
>>
>> --
>>  M S   Herfried K. Wagner
>> M V P  <URL:http://dotnet.mvps.org/>
>>  V B   <URL:http://classicvb.org/petition/>
>>
>>
Author
16 Jul 2006 12:32 PM
naraby
if you are using VB6
use var1 = left(var2,60)
or use var1 = mid(var2,1,60)

If you are using VB.net
use var1 = var2.substring(1,60)


Show quoteHide quote
"John" wrote:

> I have a string that is 100 characters long, I need to get the first 50, How
> can I do that in VB?
> I haven't coded in VB in years and I forget the syntax for it.
>
>
>
>
>