SIMIN Posted January 4, 2009 Posted January 4, 2009 Hi, I want to convert this VB6 code to VB.NET: Private Function StripNullChars(ByVal MyString As String) As String Do While Len(MyString) > 0 If Asc(VB.Right(MyString, 1)) <> 0 Then Exit Do MyString = VB.Left(MyString, Len(MyString) - 1) Loop StripNullChars = MyString End Function However, I don't know what are replacements .NET version of VB.Left and VB.Right? Please help me. Thanks. Quote
Administrators PlausiblyDamp Posted January 4, 2009 Administrators Posted January 4, 2009 The .SubString(...) method of the string type is the best match, however you may find using .Trim easier as it will strip any character you specify from a string. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
SIMIN Posted January 4, 2009 Author Posted January 4, 2009 hi thanks and many thanks for all your valuable helps :) I am a little bit confused so my final converted code would be: Private Function StripNullChars(ByVal MyString As String) As String StripNullChars = MyString.Trim(vbNull) End Function you mean? but it has error thanks again :) Quote
Administrators PlausiblyDamp Posted January 4, 2009 Administrators Posted January 4, 2009 Does the following work? Return MyString.Trim(Convert.ToChar(0)) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
SIMIN Posted January 4, 2009 Author Posted January 4, 2009 Hi and thanks :) you are so kind I just replaced it in my code and it's working, I think so :) sorry but for final confirm we can say that these 2 codes are the same now? code1: Private Function StripNullChars(ByVal MyString As String) As String Do While Len(MyString) > 0 If Asc(VB.Right(MyString, 1)) <> 0 Then Exit Do MyString = VB.Left(MyString, Len(MyString) - 1) Loop StripNullChars = MyString End Function code2: Private Function StripNullChars(ByVal MyString As String) As String StripNullChars = MyString.Trim(Convert.ToChar(0)) End Function Quote
Administrators PlausiblyDamp Posted January 5, 2009 Administrators Posted January 5, 2009 Technically the original would only strip nulls from the right end of a string while the second version would strip from the start and end (not that you would expect them on the start). If you only wanted to remove from the end .TrimEnd() would be a better choice. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
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.