473,857 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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).ToS tring(); //"˘"
byte[] btVal = System.Text.ASC IIEncoding.ASCI I.GetBytes(str) ;
string str2 = System.Text.ASC IIEncoding.ASCI I.GetString(btV al);
--- Code -------------------------------

regards, jazper


Nov 15 '05 #1
5 1367
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.o rg> schrieb im Newsbeitrag
news:O2******** ******@TK2MSFTN GP10.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(s tr);
string str2=Encoding.U TF8.GetString(b ytes);

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.o rg> schrieb im Newsbeitrag
news:O2******* *******@TK2MSFT NGP10.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************ ***********@hot mail.com> wrote in message
news:ka******** *************** *********@4ax.c om...
Try one of the static Encoding methods:

string str=((char)244) .ToString();
byte[] bytes=Encoding. UTF8.GetBytes(s tr);
string str2=Encoding.U TF8.GetString(b ytes);

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.o rg> schrieb im Newsbeitragnews:O2******* *******@TK2MSFT NGP10.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************ ***********@hot mail.com> wrote in message
news:ka******** *************** *********@4ax.c om...
Try one of the static Encoding methods:

string str=((char)244) .ToString();
byte[] bytes=Encoding. UTF8.GetBytes(s tr);
string str2=Encoding.U TF8.GetString(b ytes);

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.o rg> schrieb im Newsbeitragnews:O2******* *******@TK2MSFT NGP10.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
17431
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 method like: byte bin2hex(byte) {} BRs, Zulik
38
3558
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 = serial.Serial()
51
8315
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 code? many thx!
3
1135
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
4873
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 report=<abc>abc</abc>, it takes report as empty string as it assumes & as delimeter. So how can I pass as xml in http post request. Thanks, Sushi
4
6709
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 perfectly, but not when sending to DOS: Private Function bytearray2string(ByVal input As Byte()) As String Dim output As String
4
1770
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
6668
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 memStream.Write(bytes,0.bytes.length)
30
3997
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 array. Of course, when memory allocation occurs, then naturally extra processing power is needed. To more explicit, MFC introduced a super-efficient method of dealing with this situation. As far as I remember (I switched from MFC to .NET few...
4
2568
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 extract the data in substrings of 4 chars, and convert this with Cdbl(my substring), but I get an InvalidCastException in the conversion. Example of the spectrum data:  ■├Đ ■╔L ■├ ■╦: ■▓° ■┬& ■ĂA ■« ■─5 ■╬% ■╣╗ ■╩
0
9923
marktang
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...
0
9767
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,...
1
10807
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9549
agi2029
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...
1
7939
isladogs
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...
0
7104
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();...
0
5774
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...
1
4592
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 we have to send another system
3
3215
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 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...

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.