Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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 :)

Posted

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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...