substring, left, right function ?

A

Agnes

in .net , any left function ??
or I should use Microsoft.VisualBasic.Left(myString, 5)
Thanks
 
O

One Handed Man \( OHM - Terry Burns \)

Dim a As String = "ABCDEF"

Debug.WriteLine(a.Substring(0, 5))

'Returns ABCDE


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
H

Herfried K. Wagner [MVP]

* "Agnes said:
in .net , any left function ??
or I should use Microsoft.VisualBasic.Left(myString, 5)

I suggest to use VB.NET's 'Left' function because it is more descriptive
than the string's 'Substring' method.
 
J

Jay B. Harlow [MVP - Outlook]

Agnes,
The Left function in .NET is Microsoft.VisualBasic.Strings.Left!

If you use Strings.Left you may want to use an Import alias on
Microsoft.VisualBasic.

Imports VB = Microsoft.VisualBasic

Dim myString As String
myString = VB.Left(myString, 5)

Especially in Window Forms, as Left is a property of Control.

An alternative to Microsoft.VisualBasic.Strings is the methods on String
itself (such as String.SubString). I normally use String.SubString instead
of Strings.Left, however both are equally valid.

The one caveat I recommend is do not mix the VB Strings functions with the
String methods, as VB Strings are 1 based indexes & the String methods are 0
based indexes.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top