bungpeng Posted October 29, 2003 Posted October 29, 2003 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? Quote
Administrators PlausiblyDamp Posted October 29, 2003 Administrators Posted October 29, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
themster Posted October 29, 2003 Posted October 29, 2003 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. Quote
Moderators Robby Posted October 29, 2003 Moderators Posted October 29, 2003 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. Quote Visit...Bassic Software
bungpeng Posted October 30, 2003 Author Posted October 30, 2003 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...:) Quote
Moderators Robby Posted October 30, 2003 Moderators Posted October 30, 2003 SubString replaces Mid as well Quote Visit...Bassic Software
CattleRustler Posted November 8, 2003 Posted November 8, 2003 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! Quote mod2software Home of the VB.NET Class Builder Utility - Demo and Full versions available now!
Administrators PlausiblyDamp Posted November 9, 2003 Administrators Posted November 9, 2003 Insttead of InStr and instrRev you could (in fact should) use string.IndexOf or string.LastIndexOf Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
themster Posted November 9, 2003 Posted November 9, 2003 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. Quote
Leaders dynamic_sysop Posted November 9, 2003 Leaders Posted November 9, 2003 you certainly can replace chars with SubString :) eg: 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.