Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,943 questions

51,883 answers

573 users

How to convert a string with pairs of numbers to an array of bytes without converting in VB.NET

1 Answer

0 votes
Imports System
Imports System.Text

Public Class Program
    Public Shared Sub PrintByteArray(ByVal bytes As Byte())
        Dim sb = New StringBuilder("byte[] = ")
        Dim b
 
        For Each b In bytes
            sb.Append(b & ", ")
        Next
 
        Console.WriteLine(sb.ToString())
    End Sub
    
    Public Shared Sub Main()
        Dim str As String = "97987099304825"
        Dim bytes((str.Length / 2) - 1) As Byte

        For i As Integer = 0 to str.Length - 1 Step 2
            bytes(i / 2) = Convert.ToByte(str.Substring(i, 2))
        Next i

        Console.WriteLine(Encoding.UTF8.GetString(bytes))
        
        PrintByteArray(bytes)

    End Sub
End Class




' run:
'
' abFc0
' byte[] = 97, 98, 70, 99, 30, 48, 25, 
'

 



answered May 28, 2024 by avibootz

Related questions

...