473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

vb.net byte array string copy

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
3 12761
<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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tomas Deman | last post by:
Hi, I need a fast method for converting an int array to a byte array. At the moment, I'm using this: public static byte Int2ByteArray(int array) { byte lbytRetval = new byte; int lintIdxHi;...
1
by: Me | last post by:
I'm trying to get a structure into a byte array. I can't seem to figure out how to get a non-fixed length null-terminated string into the array (without rolling my own logic). For example, a...
5
by: Robin Tucker | last post by:
I need to marshal an IntPtr (which I've got from GlobalLock of an HGLOBAL) into a byte array. I know the size of the array required and I've got a pointer to the blob, but I can't see how to copy...
4
by: Lance | last post by:
I have an array of bytes that I need to convert into an array of Integers. But, the number of bits per value in the Byte array is not necessarily divisible by 8 (although it will never exceed...
5
by: Terry Olsen | last post by:
Looking for info on how to convert a byte array to a string, and string to byte array. Thanks.
2
by: twawsico | last post by:
I have a piece of code that needs to read the contents of a binary file (that I've created with another app) into an array of structures. The binary data in the file represents just a series of...
2
by: TonyJ | last post by:
Hello! Now to my question. Here I copy from a byte array into another byte array and then convert to a string. Is it possible to convert some part from a byte array into a string directly...
10
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
2
by: TaeMike | last post by:
Hello, I have some varchar(2000) fields in my tables, and they have a lot of "weird" characters in them including line break and carriage returns, etc. When I do a select, I see the entire string of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.