String to Byte Array convertion?!

me_again

Newcomer
Joined
Mar 26, 2003
Messages
14
Location
Boksburg, South Africa
(RESOLVED) String to Byte Array convertion?!

Hi everyone,

String to Byte Array convertion?!

I've searched the forum for similar posts but couldn't seem to find any that satisfied my question.

In VB6 you could convert a String to a Byte array using
Visual Basic:
Dim buffer
Dim sStr As String
   'String to Byte Array
   buffer = StrConv(sStr, vbFromUnicode)
   'and back to string
   sStr = StrConv(buffer, vbUnicode)

How on earth do you do the same type of thing in VB.NET?

I need to do this for an Overloaded function - one function excepts a String parameter and the next function excepts a Byte array parameter. I then call the latter from the first, and want to pass the 'converted' string into the Byte array parameter.

Thanks in advance.
 
Last edited:
(RESOLVED) String to Byte Array convertion?!

It's amazing what can be achieved when the old grey matter is put into action.

I followed to old trusted method : Wrote what I wanted in VB6 and had .NET's upgrade wizard handle the rest.

This is what i got:

VB6 CODE:
Visual Basic:
Public Sub Main()
   Dim s As String
   Dim b() As Byte
   
   s = "Some String"
   
   b = StrConv(s, vbFromUnicode)
   s = vbNullString
   s = StrConv(b, vbUnicode)
End Sub

VB.NET CODE:
Visual Basic:
Public Sub Main()
   Dim s As String
   Dim b() As Byte

   s = "Some String"

   b = System.Text.UnicodeEncoding.Unicode.GetBytes(s)
   s = vbNullString
   s = System.Text.UnicodeEncoding.Unicode.GetString(b)
End Sub

Problem solved!
 
Back
Top