The choice of encoding depends on what you want to do with resutling
sequence of bytes.
You can't tell that one encoding is "better" than other. If your original
string is known to contain only ASCII character (\u0000-\u007F), your
solution is fine. oll other characters will be replaced with '?'. But if
you want to encode arbitrary international strings without loss of
information, UnicodeEncoding or UTF8 encoding should be used. Please keep
in mind that every unicode character in the original string can be
represented by more than one byte in a resulting byte stream. In case of
Unicode encoding it's 2 bytes per unicode character (endianess is
important), in case of UTF8 it's variable length (1-4 bytes per Unicode
character).
- Roman
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| NNTP-Posting-Date: Tue, 20 Jan 2004 19:20:57 -0600
| From: "Gordon Freeman" <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| References: <#
[email protected]>
<
[email protected]>
<
[email protected]> <
[email protected]>
<
[email protected]>
| Subject: Re: String to StreamReader
| Date: Tue, 20 Jan 2004 20:20:48 -0500
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <
[email protected]>
| Lines: 19
| NNTP-Posting-Host: 68.54.189.138
| X-Trace:
sv3-dmQSN4qGf6M6HgyTNQWm+/DUxgKquI42sCo8pU78uKrdreKbtmx9+odyDUkNUk/jliaTV8Lv
o4s4LsD!kQ6tNHSfG5RVfdNxaKY/1K5AvrSnWcqEqhAThBX0Md9aA0JRcHRKOne75O8t0A==
| X-Complaints-To: (e-mail address removed)
| X-DMCA-Complaints-To: (e-mail address removed)
| X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
| X-Postfilter: 1.1
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!newsfe
ed.icl.net!newsfeed.fjserv.net!news.maxwell.syr.edu!newshosting.com!nx02.iad
01.newshosting.com!216.196.98.140.MISMATCH!border1.nntp.ash.giganews.com!bor
der2.nntp.sjc.giganews.com!border1.nntp.sjc.giganews.com!nntp.giganews.com!l
ocal1.nntp.sjc.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for
-mail
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.compactframework:43581
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Thanks for pointing out the problem. So what is the solution Roman? Would
| using UTF8Encoding be better than ASCIIEncoding?
|
| | > | Imports System.IO
| > | Imports System.Text
| > | ...
| > | Public Function GetSR(ByVal Input As String) As StreamReader
| > | GetSR = New StreamReader(New MemoryStream(New
| > | ASCIIEncoding().GetBytes(Input)))
| > | End Function
| >
| > Please note that this solution won't work if you string contains any
| > non-ASCII characters.
| >
| > - Roman
|
|
|
This posting is provided "AS IS" with no warranties, and confers no rights.