473,379 Members | 1,201 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,379 software developers and data experts.

simple conversion string->bytes->string changes my data???

hi

can anybody explain that to me:
i did the following:
- 1. input of char 244 ("ô") into string
- 2. convert to getbytes
- 3. convert back to string

char 244 changed to char 63 ("?")
why??? what can i do the get the same string...?

--- Code -------------------------------
string str = ((char)244).ToString(); //"ô"
byte[] btVal = System.Text.ASCIIEncoding.ASCII.GetBytes(str);
string str2 = System.Text.ASCIIEncoding.ASCII.GetString(btVal);
--- Code -------------------------------

regards, jazper


Nov 15 '05 #1
5 1347
char 244 changed to char 63 ("?")
why???


244 is not a 7-bit ASCII character. See

http://www.joelonsoftware.com/articles/Unicode.html
http://www.yoda.arachsys.com/csharp/unicode.html

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
plz dont let me beg and weep...
how can i solve my problem. (i dont want to read a book about utf-8 to solve
this little problem) :-)

so, where can i set the encoding type for GetBytes() and GetString()?

pleeeeease...
Jazper.


"Mattias Sjögren" <ma********************@mvps.org> schrieb im Newsbeitrag
news:O2**************@TK2MSFTNGP10.phx.gbl...
char 244 changed to char 63 ("?")
why???


244 is not a 7-bit ASCII character. See

http://www.joelonsoftware.com/articles/Unicode.html
http://www.yoda.arachsys.com/csharp/unicode.html

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 15 '05 #3
Try one of the static Encoding methods:

string str=((char)244).ToString();
byte[] bytes=Encoding.UTF8.GetBytes(str);
string str2=Encoding.UTF8.GetString(bytes);

Austin Ehlers

On Fri, 7 Nov 2003 00:27:39 +0100, "Jazper" <j.***@bluewin.ch> wrote:
plz dont let me beg and weep...
how can i solve my problem. (i dont want to read a book about utf-8 to solve
this little problem) :-)

so, where can i set the encoding type for GetBytes() and GetString()?

pleeeeease...
Jazper.


"Mattias Sjögren" <ma********************@mvps.org> schrieb im Newsbeitrag
news:O2**************@TK2MSFTNGP10.phx.gbl...
>char 244 changed to char 63 ("?")
>why???


244 is not a 7-bit ASCII character. See

http://www.joelonsoftware.com/articles/Unicode.html
http://www.yoda.arachsys.com/csharp/unicode.html

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.


Nov 15 '05 #4
cool, thank you for your short solution, austin.
works fine!
cheers, jazper
"Austin Ehlers" <th***********************@hotmail.com> wrote in message
news:ka********************************@4ax.com...
Try one of the static Encoding methods:

string str=((char)244).ToString();
byte[] bytes=Encoding.UTF8.GetBytes(str);
string str2=Encoding.UTF8.GetString(bytes);

Austin Ehlers

On Fri, 7 Nov 2003 00:27:39 +0100, "Jazper" <j.***@bluewin.ch> wrote:
plz dont let me beg and weep...
how can i solve my problem. (i dont want to read a book about utf-8 to solvethis little problem) :-)

so, where can i set the encoding type for GetBytes() and GetString()?

pleeeeease...
Jazper.


"Mattias Sjögren" <ma********************@mvps.org> schrieb im Newsbeitragnews:O2**************@TK2MSFTNGP10.phx.gbl...

>char 244 changed to char 63 ("?")
>why???

244 is not a 7-bit ASCII character. See

http://www.joelonsoftware.com/articles/Unicode.html
http://www.yoda.arachsys.com/csharp/unicode.html

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 15 '05 #5
cool, thank you for your short solution, austin.
works fine!
cheers, jazper
"Austin Ehlers" <th***********************@hotmail.com> wrote in message
news:ka********************************@4ax.com...
Try one of the static Encoding methods:

string str=((char)244).ToString();
byte[] bytes=Encoding.UTF8.GetBytes(str);
string str2=Encoding.UTF8.GetString(bytes);

Austin Ehlers

On Fri, 7 Nov 2003 00:27:39 +0100, "Jazper" <j.***@bluewin.ch> wrote:
plz dont let me beg and weep...
how can i solve my problem. (i dont want to read a book about utf-8 to solvethis little problem) :-)

so, where can i set the encoding type for GetBytes() and GetString()?

pleeeeease...
Jazper.


"Mattias Sjögren" <ma********************@mvps.org> schrieb im Newsbeitragnews:O2**************@TK2MSFTNGP10.phx.gbl...

>char 244 changed to char 63 ("?")
>why???

244 is not a 7-bit ASCII character. See

http://www.joelonsoftware.com/articles/Unicode.html
http://www.yoda.arachsys.com/csharp/unicode.html

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 15 '05 #6

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

Similar topics

5
by: Zulik | last post by:
Hello, I might have a bad day today but I have a byte buffer holding binary numbers. Now, I want to convert this to byte buffer with hex numbers. Is there any elegant way of doing that? Some...
38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
3
by: user | last post by:
Hello i have(had) several problems durring convesrion. For example: how can i convert String to byte array ? (byte b = .....) (i need it for Socket.Send()) Thanx
4
by: sushi | last post by:
Hello, I want to make an http post request to a site. I want to pass a paramaeter having xml such as report=<abc>abc</abc> to it. When I try to do this, is gives exception. And If send...
4
by: I.Charitopoulos | last post by:
The reason I want to do so, is that I am sending to DOS and I am pretty certain that it will not work. Everything I've tried so far hasnt. In my test environment (Windows to Windows) this works...
4
by: Emilio | last post by:
Question about Shared Sub Connect(server As , message As ) Why is in square brackets? Is it like Shared Sub Connect(server() As String, message() As String)
3
by: grawsha2000 | last post by:
Hi, I'm trying to convert this simple string into image: Dim bytes() as byte()=System.text.Encoding.ascii.GetBytes("123") Dim memStream as System.IO.MemoryStream Dim img as image ...
30
by: nano2k | last post by:
Hi I need an efficient method to convert a string object to it's byte equivalent. I know there are LOTS of methods, but they lack in efficiency. All methods allocate new memory to create the byte...
4
by: Freddy Coal | last post by:
Hi, I'm recovery data from an spectrum analizer, the equipment send me data in binary, each data in the trace have 4 bytes, I would like convert that to double, how make that?. I'm trying...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.