473,480 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to convert back a string that have converted to byte[]

How to convert back a string that have converted to byte[] using
System.Text.Encoding.UTF8.GetBytes()

string StringData = "This is a string";
byte[] ConvertedString = System.Text.Encoding.UTF8.GetBytes(StringData);

Now, how can I convert ConvertedString to "This is a string" string again?
Nov 16 '05 #1
8 2040
"FrzzMan" <Fr***************@vnOCzone.com> wrote in message
news:Os****************@TK2MSFTNGP10.phx.gbl...
How to convert back a string that have converted to byte[] using
System.Text.Encoding.UTF8.GetBytes()

string StringData = "This is a string";
byte[] ConvertedString = System.Text.Encoding.UTF8.GetBytes(StringData);

Now, how can I convert ConvertedString to "This is a string" string again?


System.Text.Encoding.UTF8.GetString

Erik
Nov 16 '05 #2
FrzzMan wrote:
How to convert back a string that have converted to byte[] using
System.Text.Encoding.UTF8.GetBytes()

string StringData = "This is a string";
byte[] ConvertedString =
System.Text.Encoding.UTF8.GetBytes(StringData);

Now, how can I convert ConvertedString to "This is a string" string
again?


string System.Text.Encoding.UTF8.GetString(byte[]);

--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
Nov 16 '05 #3
FrzzMan wrote:
How to convert back a string that have converted to byte[] using
System.Text.Encoding.UTF8.GetBytes()

string StringData = "This is a string";
byte[] ConvertedString = System.Text.Encoding.UTF8.GetBytes(StringData);

Now, how can I convert ConvertedString to "This is a string" string again?


Oops sorry, I didn't know there's GetString method... sry...
Nov 16 '05 #4
..NET GetBytes() and GetString() didn't work right with UTF-8 charset.

My following code prove that...

string Data = "UTF-8 string"; // <-- Insert some *long* UTF-8 string
byte[] DataBytes = System.Text.Encoding.UTF8.GetBytes(Data);
string BackConvert = System.Text.Encoding.UTF8.GetString(DataBytes);

System.IO.StreamWriter File = System.IO.File.CreateText("test.txt");
File.Write(Data + "\n" + BackConvert);
File.Close();

Wait a lil, see the attached text file, open it with your browser and
set browser text encoder to UTF-8, you'll see the different...
Nov 16 '05 #5
FrzzMan <Fr***************@vnOCzone.com> wrote:
.NET GetBytes() and GetString() didn't work right with UTF-8 charset.

My following code prove that...

string Data = "UTF-8 string"; // <-- Insert some *long* UTF-8 string
byte[] DataBytes = System.Text.Encoding.UTF8.GetBytes(Data);
string BackConvert = System.Text.Encoding.UTF8.GetString(DataBytes);

System.IO.StreamWriter File = System.IO.File.CreateText("test.txt");
File.Write(Data + "\n" + BackConvert);
File.Close();

Wait a lil, see the attached text file, open it with your browser and
set browser text encoder to UTF-8, you'll see the different...


Um, I doubt it, to be honest. You'll need to give us a sample string to
show us what you mean.

To check that the strings are the same, you could just use

Console.WriteLine (Data==BackConvert);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
I doubt it, too... but I did try and it didn't work... in the last post
I forgot to attach the result with sample string, my fault...

In this post I attached the result file of the test, and I tried to
System.Console.WriteLine(Data == BackConvert) before, it give me a False.

You can try it yourself... use the first line in the attached file as
the sample string...

Jon Skeet [C# MVP] wrote:
FrzzMan <Fr***************@vnOCzone.com> wrote:
.NET GetBytes() and GetString() didn't work right with UTF-8 charset.

My following code prove that...

string Data = "UTF-8 string"; // <-- Insert some *long* UTF-8 string
byte[] DataBytes = System.Text.Encoding.UTF8.GetBytes(Data);
string BackConvert = System.Text.Encoding.UTF8.GetString(DataBytes);

System.IO.StreamWriter File = System.IO.File.CreateText("test.txt");
File.Write(Data + "\n" + BackConvert);
File.Close();

Wait a lil, see the attached text file, open it with your browser and
set browser text encoder to UTF-8, you'll see the different...

Um, I doubt it, to be honest. You'll need to give us a sample string to
show us what you mean.

To check that the strings are the same, you could just use

Console.WriteLine (Data==BackConvert);

miniLZO -- mini subset of the LZO real-time data compression library Đây l* tiếng Việt, nén th* coi có được không n*o... Đây l* tiếng Việt, nén th* coi có được không n*o... Đây l* tiếng Việt, nén th* coi có được không n*o... Đây l* tiếng Việt, nén th* coi có được không n*o... Đây l* tiếng Việt, nén th* coi có được không n*o... Đây l* tiếng Việt, nén th* coi có được không n*o... Đây l* tiếng Việt, nén th* coi có được không n*o...
miniLZO -- mini subset of the LZO real-time data compression library Đây l* tiếng Việt, nén th* coi có được không n*o... Đây l* tiếng Việt, nén th* coi có được không n*o... Đây l* tiếng Việt, nén th* coi có được không n*o... Đây l* tiếng Việtꀜҥnén th* coi cóꁦҥược không n*o... Đây l* tiếng Việt, nén ꀰҥ* coi có được không n*o... Đây l* tiếng ꁶҥệt, nén th* coi có được không n*o... Đây l* tiếng Việt, nén th* coi có được không ꂍҥo...

Nov 16 '05 #7
FrzzMan <Fr***************@vnOCzone.com> wrote:
I doubt it, too... but I did try and it didn't work... in the last post
I forgot to attach the result with sample string, my fault...

In this post I attached the result file of the test, and I tried to
System.Console.WriteLine(Data == BackConvert) before, it give me a False.

You can try it yourself... use the first line in the attached file as
the sample string...


You haven't actually really attached a file - just cut and paste it.
Please email me an example and I'll have a look at it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
Thanks, .rar file mailed... I still can't get it working...

Jon Skeet [C# MVP] wrote:
FrzzMan <Fr***************@vnOCzone.com> wrote:
I doubt it, too... but I did try and it didn't work... in the last post
I forgot to attach the result with sample string, my fault...

In this post I attached the result file of the test, and I tried to
System.Console.WriteLine(Data == BackConvert) before, it give me a False.

You can try it yourself... use the first line in the attached file as
the sample string...

You haven't actually really attached a file - just cut and paste it.
Please email me an example and I'll have a look at it.

Nov 16 '05 #9

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

Similar topics

1
4432
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
13
41766
by: Hako | last post by:
I try this command: >>> import string >>> string.atoi('78',16) 120 this is 120 not 4E. Someone can tell me how to convert a decimal number to hex number? Can print A, B, C,DEF. Thank you.
6
10124
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
3
52438
by: Jan Eliasen | last post by:
Hi I have a string, which I must convert into another string and have it utf-8 encoded. My current code looks like this; Both vDataIn and vDataOut are Objects (parameters to a...
25
7216
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
10
8004
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
6
53665
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
10
4906
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
0
10702
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
6908
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
7084
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...
1
6739
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...
0
4481
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...
0
2995
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...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
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 ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
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...

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.