Andrea Tand Andrea Tand - 3 months ago 7
Vb.net Question

VB.Net looping through a string

I have a string say "768932A3" that I want split up into two's like this:
76 89 32 A3 for purposes of conversion to binary. I have tried looping but it doesn't work. Kindly help:

For i = 0 To data.Length - 1

j = i + 2
incremented &= Convert.ToInt64(data.Substring(i, j), 16)
ascii &= Chr(Convert.ToInt64(data.Substring(i, j), 16))
i = j + 2

Next

Answer

The second parameter of Substring is not the ending position but the lenght of characters to consider from the starting position.

For i = 0 To data.Length - 1 Step 2
    ' Not clear what are you trying to do here 
    ' incremented &= Convert.ToInt64(data.Substring(i, 2), 16)

    Dim value As Long = Convert.ToInt64(data.Substring(i, 2), 16)


    ascii &= Chr(Convert.ToInt64(data.Substring(i, 2), 16))
Next
Comments