VB "Left"

bungpeng

Senior Contributor
Joined
Sep 10, 2002
Messages
906
Location
Malaysia
VB "Left" and "Right" function is not available in VB.NET?

May I know what other functions in VB are not available in VB.NET? Any references?
 
Visual Basic:
Dim s as string = "test String"
MessageBox.Show (s.Substring(1,2))

would be the equivalent of Left$ - by using different parameters for the .SubString method you can acheive the same as Left$, Right$, mid$ etc.
 
Imports

You need to import the namespace that includes the Left function.
Include this first in your code, before any declaration.

Imports Txt = Microsoft.VisualBasic.Strings

You can then use the following syntax to access the Left function.

Txt.Left("testing,2)

You can you the Object Browser to search for the function you are looking for and then include the required namespace using Imports.
 
Use SubString() as PlausiblyDamp pointed out, stay away from legacy VB specic code. If you ever need to port your VB code to C# wouldn't you like it to be as seamless as possible.
 
Thank you! currently I am using SubString to replace left and right. But "Mid" is still available right?

Just felt that "Right" is not so conveninet to replace with SubString...:)
 
Mid() is still available, which you can use to do anything you could with left() or right() functions, also you can use substring like stated above, and you can still use instr() and instrrev()

so everything should be peachy!
 
I might be me, but I can't use substring to replace chars within strings like I can with mid. I have tried to use Insert but it doesn't seem to replace, it only inserts new chars.
 
you certainly can replace chars with SubString :) eg:
Visual Basic:
        Dim strString As String = "abc123"
        Dim strNewString As String = strString.Replace(strString.Substring(1, 1), "B")
        MessageBox.Show(strNewString) '/// b will be replaced with B
 
Back
Top