Author Topic: Converting byte array to char array  (Read 1103 times)

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Converting byte array to char array
« 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.
« Last Edit: July 21, 2016, 10:08:23 PM by bachphi »
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Converting byte array to char array
« Reply #1 on: July 21, 2016, 10:11:02 PM »
I got it:

charArray = BitConverter.ToString(comBuffer).Replace("-", " ").ToCharArray()
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================