ThunderMusic,
You really need to use the encoding that is being sent to you.
The "easiest" way may be to use System.Text.Encoding.Default as the
encoding, as it uses 8-bit character code points.
| if I use Unicode
| Encoding, the resulting string is 4096 bytes long and if I use
UTF8Encoding,
| the resulting string is 4594 bytes long starting from a 8195 bytes long
byte
That sounds about right, as UnicodeEncoding is UTF-16 which means that each
"character" is stored in 2 bytes. Where as UTF8Encoding is UTF-8 which means
that each "character" is stored in 1, 2, 3, and sometimes 4 bytes.
System.Text.Encoding.Default is your ANSI encoding as set under Windows
Control Panel Regional settings. ANSI is an 8-bit encoding, so each byte
represents a single character. The "danger" of using Encoding.Default is
characters being translated incorrectly...
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
| Hi,
|
| ok, I tried UnicodeEncoding and UTf8Encoding, but it does not work as I
| would like it to work. You see, the way it works right now, if I use
Unicode
| Encoding, the resulting string is 4096 bytes long and if I use
UTF8Encoding,
| the resulting string is 4594 bytes long starting from a 8195 bytes long
byte
| array. In this array, each byte is containing a useful character, even if
| this character is not between a and z or anything like that, each byte is
| important, so I really need something that will convert directly this byte
| array into a string where I can use string.indexof and all those things or
| something similar to it.
|
| Maybe some of you have other ideas on how I should do this, I explain the
| case a little : I connect to a socket, this socket sends me a byte array.
In
| this byte array, there are some useful infos I have to search for, so in a
| string format I use TheString.IndexOf("InfoToSearch", 0) and it should
find
| "InfoToSeach" and return me the position where it is in the string. If
there
| is a way to do the same thing using directly the Byte() or a Stream of
some
| sort, Fine! please thell me, but now, it's the only way I found. :(
|
| Please help!! I really need it.
|
| Thanks
|
| "Herfried K. Wagner [MVP]" <hi***************@gmx.at> a écrit dans le
| message de news: Or**************@TK2MSFTNGP09.phx.gbl...
| > "ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> schrieb:
| >> I have to go from Byte() to String, do some processing then reconvert
the
| >> String to byte() but using ascii format, not unicode.
| >
| > 'System.Text.Encoding.<encoding>.{GetString, GetBytes}'.
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|