get first 50 characters

  • Thread starter Thread starter John
  • Start date Start date
J

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.
 
There are a few different ways you can try:

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

are a couple...

Cory
 
John said:
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)'.
 
Stuart Nathan said:
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.
 
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
 
Cor Ligthert said:
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'.
 
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,

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
 
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)
 
Back
Top