
Converting from string to array of bytes
You would use an encoding object, like I said.
To get the literal results that you would get below, you would use
Encoding.Default (to get the default system code page) but on the
whole I would recommend a better choice since that will change
behavior between machines when the CP_ACP changes.
You would use the GetBytes method off that object -- you pass in the
string and it spits out the bytes.
--
MichKa
This posting is provided "AS IS" with
no warranties, and confers no rights.
Quote:
> I have a string that I want to pass to a function that accepts an
array of
> bytes. I could code the "translation" as:
> For i = 0 to MyStr.Length - 1
> MyByteArray(i) = Asc(MyStr.Chars(i))
> Next
> FunctionXYZ(MyByteArray)
> I'm just attempting to determine if there's a generic built-in
routine as
> that would be the preferred method, before using my own code.
> Richard Rosenheim
in
> > Generally you would use the Encoding class for this, choosing an
encoding
> to match how you want the
> > translation to take place. What is the form you expect for the
reulting
> byte array?
> > --
> > MichKa
> > This posting is provided "AS IS" with
> > no warranties, and confers no rights.
> > > Is there a function in the Framework to convert a string to an
array of
> > > bytes?
> > > Richard Rosenheim