substring, left, right function ?

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

in .net , any left function ??
or I should use Microsoft.VisualBasic.Left(myString, 5)
Thanks
 
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
 
* "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.
 
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

Back
Top