vb.net byte array string copy

M

marfi95

Hi all.

I need to copy a byte array into a string, but starting at a specific
location in the byte array. This is where I get hung up. For example if
my byte array is (100) big, I might want to start at position 60 for
example and copy from 60 to the next null byte in the array to my
string. The starting position is variable, as is where the next null
byte is in the byte array.

The array I'm dealing with is much bigger than that, so doing it char
by char (which is what I was doing) is way, way too slow.

Many TIA.
 
H

Herfried K. Wagner [MVP]

I need to copy a byte array into a string, but starting at a specific
location in the byte array. This is where I get hung up. For example if
my byte array is (100) big, I might want to start at position 60 for
example and copy from 60 to the next null byte in the array to my
string. The starting position is variable, as is where the next null
byte is in the byte array.

'System.Text.Encoding.<encoding>.GetString(<bytes>, <index>, <count>)'.
 
C

Christiaan Nijdam

Did you use StringBuilder as in?:

Dim sb As New System.Text.StringBuilder(1000)
Dim i As Integer
Dim b As Byte() = {65, 66, 67, 68, 69}
For i = b.GetLowerBound(0) To b.GetUpperBound(0)
sb.Append(ChrW(b(i)))
Next
Console.WriteLine(sb)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top