If I run the following code:
Byte[] bytes = System.Text.Enc oding.ASCII.Get Bytes("test");
return BitConverter.To String(bytes);
I get the string "74-65-73-74" back. My question is, what is the
easiest way to convert the string back to "test"?
Can it be done without breaking the string and using a loop, etc.? I
have tried many methods, but can't find a way without using a loop. It
seems silly that the framework can go one direction but not the other.
Any help please? 4 16236
System.Text.Enc oding.ASCII.Get String(bytes);
i think that's what you're looking for.
Chris
"Greg Ennis" <gr*****@gmail. com> wrote in message
news:a8******** *************** ***@posting.goo gle.com... If I run the following code:
Byte[] bytes = System.Text.Enc oding.ASCII.Get Bytes("test"); return BitConverter.To String(bytes);
I get the string "74-65-73-74" back. My question is, what is the easiest way to convert the string back to "test"?
Can it be done without breaking the string and using a loop, etc.? I have tried many methods, but can't find a way without using a loop. It seems silly that the framework can go one direction but not the other.
Any help please?
Chris <ct******@hotma il.com> wrote: System.Text.Enc oding.ASCII.Get String(bytes);
i think that's what you're looking for.
I don't think so - that certainly doesn't do the reverse of
BitConverter.To String.
For me, BitConverter.To String is really for debug purposes, to easily
see the values in a byte array. That's why (I believe) there's no
reverse method.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too System.Text.En coding.ASCII.Ge tString(bytes);
i think that's what you're looking for.
Thanks but this is not correct; this will give me a string of length 11
whereas I am looking for the original string of length 4. This is
because GetString() does not *decode* the hex values in the bytes.
So, I am still looking for a 1-step solution...
-Greg
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Greg,
I believe Jon is correct with his statement: For me, BitConverter.To String is really for debug purposes, to easily see the values in a byte array. That's why (I believe) there's no reverse method.
This will just give you a nice human readable representation of the bytes.
System.Text.Enc oding.ASCII.Get Bytes(string)
System.Text.Enc oding.ASCII.Get String(bytes)
would be complimentary functions dealing with the underlying data.
Just like MyObject.ToStri ng almost certainly would not give you a String from
which you could create an identical copy of your Object.
Gerald
"Greg Ennis" <no**@none.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..System.Text.En coding.ASCII.Ge tString(bytes);
i think that's what you're looking for.
Thanks but this is not correct; this will give me a string of length 11 whereas I am looking for the original string of length 4. This is because GetString() does not *decode* the hex values in the bytes.
So, I am still looking for a 1-step solution...
-Greg *** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michi Henning |
last post by:
Looking at the language spec, I can't find a statement
about the byte order for value types, such as int, float,
etc. Are they guaranteed to be little-endian or big-
endian? I know that, on a little-endian machine, the byte
order is little-endian. But what if I run C# on a big-
endian machine, say, using Mono?
Does the C# language (or IL) make any guarantees as to the
byte order?
|
by: CSharpener |
last post by:
This should be *so* easy! How do I convert a Byte or int to a binary string representation in C#
In JavaScript, it goes like this for an int:
javascript:(123).toString(2
or
javascript:(0xFE).toString(2
No problem. So, how do I do the same in C#? What simple thing am I missing
|
by: Greg Ennis |
last post by:
If I run the following code:
Byte bytes = System.Text.Encoding.ASCII.GetBytes("test");
return BitConverter.ToString(bytes);
I get the string "74-65-73-74" back. My question is, what is the
easiest way to convert the string back to "test"?
Can it be done without breaking the string and using a loop, etc.? I
have tried many methods, but can't find a way without using a loop. It
|
by: Ping |
last post by:
Hi, All,
We can use BitConverter.ToString(byte) to a string,
but how to get the byte from a string like "AD-A6-0D-1F"?
|
by: Pohihihi |
last post by:
I am getting Guid using
new Guid()
when I say
new Guid().ToString() I get 10856f25-2759-0358-159c-ff7e0759c800
but when I say
| |
by: Tedmond |
last post by:
Can anyone tell me how to convert a byte to bit pattern?
e.g. Byte b = 1; after conversion = 00000001
Tedmond
|
by: gizmo |
last post by:
Hi,
Here's a little hack I put together to try to get to the bottom of a
problem I'm having with trying to base64 encode a hash value. The hash
value contains character codes 135 and 130 amongst others.
This snippet will set up a string of chars 190, 135, 130, 73, 242, 243,
10. It puts them into a bytearray.
string encodedData;
|
by: lifeisgreat20009 |
last post by:
This is what i am getting on running the program.........
C:\PROGRA~1\Java\JDK15~1.0\bin>javac Editor.java
Note: Editor.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Below is my code with no errors but its not running.........
|
by: laszlobarta |
last post by:
Hello,
For saving 1 hour of your precious time use this function for parsing a text to a byte array:
/// <summary>
/// Converts the string representation of an array of numbers in a specified base to an
/// equivalent 8-bit unsigned integer array (byte).
/// </summary>
/// <param name="text">A System.String containing an array of numbers separated by '\r' or '\n' or '\t' or ' ' (space) or ','...
|
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: 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: 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...
|
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: 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...
|
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.
| |
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...
| |