By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

vb.net byte array string copy

P: n/a
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.

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
<ma*****@yahoo.com> schrieb:
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>)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2

P: n/a
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)


<ma*****@yahoo.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
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.

Nov 21 '05 #3

P: n/a
Marfi,

I think that you have using the sample from Herfried to create a byte array
and than copy that using the buffer class to copy that into your existing
bytearray (or do that direct without creating tempory data)

http://msdn.microsoft.com/library/de...classtopic.asp

There is as well an array.copyto method for this if you not succeed using
this.

I hope this helps,

Cor
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.