AdvancedHMI Software

General Category => Support Questions => Topic started by: bachphi on July 21, 2016, 09:48:06 PM

Title: Converting byte array to char array
Post by: bachphi on July 21, 2016, 09:48:06 PM
I'd like to convert byte array to char array. Below is what I have:
Code: [Select]
       Dim nbytes As Integer = COMPort.BytesToRead
        Dim comBuffer() As Byte = New Byte(nbytes - 1) {}        'create a byte array to hold the awaiting data
        COMPort.Read(comBuffer, 0, nbytes)                       ' {179,254,128,25,170,12}
        Dim charArray() As Char
        Dim strTemp As String = ""
        strTemp = BitConverter.ToString(comBuffer).Replace("-", " ")    'BE FE 80 19 AA 0C
        charArray = System.Text.Encoding.ASCII.GetString(comBuffer).ToCharArray()
I can do charArray = strTemp.ToCharArray() but would like to avoid using strTemp if possible.
I need charArray looks to be the same strTemp that is 'BE FE 80 19 AA 0C'. Thanks.
Title: Re: Converting byte array to char array
Post by: bachphi on July 21, 2016, 10:11:02 PM
I got it:

charArray = BitConverter.ToString(comBuffer).Replace("-", " ").ToCharArray()