473,804 Members | 3,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

copy byte array

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[30];
byte[] buffer = System.Text.Enc oding.ASCII.Get Bytes("This is a good test
for me");
string s = System.Text.Enc oding.UTF8.GetS tring(buffer);
byte[] newBuffer = new byte[30];
Array.Copy(buff er,3, newBuffer, 0, 10 );
s = System.Text.Enc oding.UTF8.GetS tring(newBuffer );
Feb 15 '08 #1
2 12738
On Feb 15, 9:52 am, "TonyJ" <johansson.ande rs...@telia.com wrote:
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?
Yes. Use the overload of Encoding.GetStr ing which takes an index and a
count as well as the byte array.

Jon
Feb 15 '08 #2
Check the overloaded version of GetString that takes an index and a count.

/claes

"TonyJ" <jo************ *****@telia.com wrote in message
news:uT******** *****@TK2MSFTNG P02.phx.gbl...
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[30];
byte[] buffer = System.Text.Enc oding.ASCII.Get Bytes("This is a good
test
for me");
string s = System.Text.Enc oding.UTF8.GetS tring(buffer);
byte[] newBuffer = new byte[30];
Array.Copy(buff er,3, newBuffer, 0, 10 );
s = System.Text.Enc oding.UTF8.GetS tring(newBuffer );


Feb 15 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2726
by: TDH | last post by:
Hi, I need to do a raw copy of a byte array to an Int16 array. For e.g., I have an byte array which has length 100, and I need to copy this to an Int16 array that has length 50. So 2 elements in the byte array gets copied to 1 element in the Int16 array. In VB6, this was easily done using CopyMemory. I need something in .NET that works as fast as CopyMemory. I
4
8829
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where a * occurs in the string). This split function should allocate a 2D array of chars and put the split results in different rows. The listing below shows how I started to work on this. To keep the program simple and help focus the program the...
5
2663
by: johannblake | last post by:
I need to copy all the data from a one dimensional byte array to a specific column in a two dimensional int array. For example: byte byteArray = {4, 5, 6}; int intArray = new int; After copying to the first column in intArray, I want the intArray to have the following data: intArray has the value 4
0
1316
by: Kirk Marple | last post by:
an external API that we're using is giving me back video data in a multi-dimensional Array (not byte, just System.Array). so, for an HD quality video, the data is organized as of bytes. i know this rather weird, but it's what i have to work with... i've been reading thru Array.Copy and other related methods, but nothing seems appropriate or efficient. i'd rather not have to copy into a big byte array and them Marshal.Copy that...
4
2945
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...
7
11646
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
3
12800
by: marfi95 | last post by:
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...
27
3394
by: JoeC | last post by:
I am still working on my game and my program is getting better. Most of what I want to works. I think I am having trouble with copy constructor. Basically I want it to copy the gdata array. My gdata will work if I do: gdata = this->get(lp); But that is not what I want to do I get some cryptic errors when I write the code like that is commented out. 49 C:\Documents and Settings\Work\My Documents\C++\Dungeon Adventure2\gaphic.cpp...
6
72912
by: =?Utf-8?B?U3VzaGlTZWFu?= | last post by:
Hello. How I can copy one byte array to other byte array? For example I have byte array1 = new byte; byte array2 = new byte; in array1 I have useful data from position 55 to 105 and I need copy those bytes to array2 on position from 15 to 65. How to do this? There are should be some function which work like "copy" function in C++.
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9160
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
7622
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
6854
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
5525
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
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.