473,386 Members | 1,867 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.

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.Encoding.ASCII.GetBytes("This is a good test
for me");
string s = System.Text.Encoding.UTF8.GetString(buffer);
byte[] newBuffer = new byte[30];
Array.Copy(buffer,3, newBuffer, 0, 10 );
s = System.Text.Encoding.UTF8.GetString(newBuffer);
Feb 15 '08 #1
2 12688
On Feb 15, 9:52 am, "TonyJ" <johansson.anders...@telia.comwrote:
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.GetString 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.comwrote in message
news:uT*************@TK2MSFTNGP02.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.Encoding.ASCII.GetBytes("This is a good
test
for me");
string s = System.Text.Encoding.UTF8.GetString(buffer);
byte[] newBuffer = new byte[30];
Array.Copy(buffer,3, newBuffer, 0, 10 );
s = System.Text.Encoding.UTF8.GetString(newBuffer);


Feb 15 '08 #3

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

Similar topics

2
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...
4
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...
5
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...
0
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...
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...
7
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...
3
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...
27
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...
6
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...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.