Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert String to SBtye Array

Status
Not open for further replies.

davida37

IS-IT--Management
May 10, 2006
113
GB
Hi,

vs2005.

how do I convert a string to a string byte array?

thanks
 


Code:
        Dim s As String = "Hello World"
        MessageBox.Show("Base String:  " & s)
        Dim b() As Byte = System.Text.UTF8Encoding.UTF8.GetBytes(s)
        MessageBox.Show("Converted from byte array to string:  " & System.Text.UTF8Encoding.UTF8.GetString(b))
 
there is a neat way of converting to char array - dont know if this is what you want
Dim test1() As Char
Dim strwork As String = "123456"
test1 = strwork.ToCharArray
 
thanks but I need this to specifically be a string byte array.
:-/

i.e MySByteArray() as sByte

you cant use .GetBytes(s) for sByte arrary.

..pulling my hair out...still..
 
I gotcha. I don't think SByte stands for String Byte. But anyways, you can try something like the following:

Code:
        Dim s As String = "Hello World"
        Dim sbs() As SByte
        Dim chars As Char() = s.ToCharArray
        For i As Integer = 0 To chars.Length - 1
            ReDim Preserve sbs(i)
            sbs(i) = Convert.ToSByte(chars(i))
        Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top