473,795 Members | 2,512 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12799
<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.En coding.<encodin g>.GetString(<b ytes>, <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.Str ingBuilder(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.WriteLi ne(sb)


<ma*****@yahoo. com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.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
407
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; int lintIdxLo; for (int i = 0; i < array.GetLength(0); i++)
1
4549
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 struct like (from another posting in this group): <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _ Private Structure SPECIFIC_SOCKET_MSG Public Length As Integer Public MsgId As Integer Public FileName As String
5
9842
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 the memory across. Using Marshal.PtrStructure doesn't work - it says my byte() array is not blittable! (byte is a blittable type however). Cannot use Marshal.Copy, because that works the other way around (for mashalling to COM, not from it). ...
4
2944
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 32). For example, lets say I have a an array of bytes (byteValues) that represents a string of 7 bit values. In this case, the first value would be stored in the first 7 bits of byteValues(0), the second value would be stored in the last bit of...
5
4196
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
4859
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 singles that correspond to those in my structure detailed below. So when I load the file, all that I know for certain is that there will be some multiple of these eight singles represented in the binary data. My code below will read the data...
2
12738
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 without having to use a temporary byte array as I have done below? //byte buffer = new byte;
10
6383
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 and then convert that to a byte array, pass it to the device, then get a reply and then convert that to a structure. I'm having issues with making sure what I've coded is correct. Cant figure out how to define an array in structure that is a...
2
36629
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 characters. When I pull them from a custom program, dts wizard, or just copy them to the clipboard, it truncates some of them. I'm guessing because it sees a line break or carriage return so it stops there. The result is that the extracted value...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.