Hi all,
I am a Beginner to c#.
I Need to convert array of byte data type to string. How to do this..
ex:
byte[] bytes = new byte[1000];
this bytes get filled up. Now I need to convert to string.
How to do this.. 5 2478
Hi,
Why not use this function:
public string writeByteArrayT oString(byte[] byteArray)
{
ASCIIEncoding ascii = new ASCIIEncoding() ;
char[] charArray = ascii.GetChars( byteArray);
return new string(charArra y);
}
Don't forget to include System.Text
Cheers,
Christiaan
<sh*********@te chie.com> schreef in bericht
news:11******** *************@g 49g2000cwa.goog legroups.com... Hi all,
I am a Beginner to c#. I Need to convert array of byte data type to string. How to do this..
ex:
byte[] bytes = new byte[1000];
this bytes get filled up. Now I need to convert to string. How to do this..
Hi,
string str = System.Text.Enc oding.ASCII.Get String (bytes);
Ab. http://joehacker.blogspot.com
<sh*********@te chie.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com... Hi all,
I am a Beginner to c#. I Need to convert array of byte data type to string. How to do this..
ex:
byte[] bytes = new byte[1000];
this bytes get filled up. Now I need to convert to string. How to do this..
Hi,
You need to know the format the bytes are in, are they ASCII, UTF8 or what?
Then you use the correct Encoding class.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<sh*********@te chie.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com... Hi all,
I am a Beginner to c#. I Need to convert array of byte data type to string. How to do this..
ex:
byte[] bytes = new byte[1000];
this bytes get filled up. Now I need to convert to string. How to do this..
Christiaan van Bergen <cv********@ber gler.nl> wrote: Why not use this function:
public string writeByteArrayT oString(byte[] byteArray) { ASCIIEncoding ascii = new ASCIIEncoding() ; char[] charArray = ascii.GetChars( byteArray); return new string(charArra y); }
Don't forget to include System.Text
Reasons not to use this function:
1) Its name doesn't follow the .NET naming conventions
2) It creates a new instance of ASCIIEncoding for no reason
3) It creates a new char array for no reason
4) It's less clear than Encoding.ASCII. GetString(whate ver);
You did ask ;)
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
<sh*********@te chie.com> wrote: Hi all,
I am a Beginner to c#. I Need to convert array of byte data type to string. How to do this..
ex:
byte[] bytes = new byte[1000];
this bytes get filled up. Now I need to convert to string. How to do this..
You need to choose the right encoding, and then ask it to decode your
bytes to a string. Unless your byte array is absolutely full of useful
data, you should specify how much of it to decode.
See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: matt melton |
last post by:
Hi there,
I am trying to write a method that accepts an array of any primitive
type and will return the same array without copying memory as an array
of bytes.
ie. I'd like to be able to do something like:
char chars = "Hello!";
byte bytes = (byte) chars;
|
by: Hal Vaughan |
last post by:
If I have a byte and I convert it to string (String sData = new
String(byte bData), then convert it back (byte bData = sData.getBytes()),
will all data be intact, or do Strings have problems with bytes that are
not printable characters? I've tested this and it seems to work fine, but
I want to make sure there isn't some condition or situation I'm not aware
of that could cause problems.
I'm doing this because it's easier to do some of my...
|
by: Govind |
last post by:
Hi All,
I want to Convert 32 bit integers to byte in right alighed format .
For 32 = the usual way is BitConverter.GetBytes(int32)==> xx xx 00 00 , but
i want right aligned like 00 00 xx xx.Is there any way.
Regards,
Govind.
|
by: Joseph Suprenant |
last post by:
I have an array of unsigned chars and i would like them converted to
an array of ints. What is the best way to do this? Using RedHat 7.3
on an Intel Pentium 4 machine. Having trouble here, hope someone can
help
Thanks
|
by: Pete Davis |
last post by:
I've never done this in C# so I don't know what the appropriate way of doing
it is.
I've got an array of bytes and I need to convert the array into "usable"
data. For example, the first 4 bytes need to be converted to an enum. The
next 4 bytes to a 32-bit int. And so on. I'm basically populating a struct
with the data. How does one do this in C#?
Thanks.
| |
by: Darrel |
last post by:
I am using binary writer to write an array of bytes to disk. However, my data starts out as an array of sbytes. I am currently type casting each array element in a for loop. Is there a faster method for converting an array of sbytes to an array of bytes?
Thanks,
Darrel
|
by: KK |
last post by:
Hi,
I need to save certain content to SQL server and then
use SQL Server indexing facility to search. SQL Server
have recomended using Image data type with a filter
type (for .htm, .doc etc..)
Now, because of this I save normal html content also
in binary format in the Image field.
|
by: intrepid_dw |
last post by:
Hello, all.
I've created a C# dll that contains, among other things, two functions
dealing with byte arrays. The first is a function that returns a byte
array, and the other is intended to receive a byte array as one of its
parameters. The project is marked for COM interop, and that all
proceeds normally.
When I reference the type library in the VB6 project, and write the
code to call the function that returns the byte array, it works
|
by: shahiz |
last post by:
basically im having null pointer exception
//read an inputstream
is = new DataInputStream(new FileInputStream("test.mpg"));
loadBytes(is);
//pass it as a datasource for the player
public void loadBytes(InputStream is){
DataSource ds=new DataSource(is);
player = Manager.createPlayer(ds);
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |