473,511 Members | 16,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Byte() to String and String to Byte(). How?

Hi,
I have to go from Byte() to String, do some processing then reconvert the
String to byte() but using ascii format, not unicode.

I currently use a stream to write the char() (BinaryWriter.Write) from the
string (String.ToCharArray), then use Stream.ToArray to convert everything
to byte(). It works most of the time, but it happens that an error tells me
something like "Additional information: Caractère de substitution faible
trouvé non précédé d'un substitut étendu à l'index : 409. Cette entrée peut
ne pas se trouver dans ce codage ou peut ne pas contenir des caractères
Unicode (UTF-16) valides." in french, so it could look something like
"Additional information: weak substitution character not preceded with an
extended substiture at the index: 409. The entry may not be found in this
coding or may not contain valid Unicode (UTF-16) characters." in english.

Can someone tell me what does it mean and what is the solution? is there
another way to do what I'm doing (I hope there is)?

Thanks

ThunderMusic
Nov 30 '05 #1
4 3379
"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/>

Nov 30 '05 #2
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/>

Nov 30 '05 #3
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/>
|
|
Nov 30 '05 #4
ok, thanks I'll try this right away... ;)
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> a écrit dans
le message de news: Oz**************@TK2MSFTNGP12.phx.gbl...
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/>
|
|

Nov 30 '05 #5

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

Similar topics

2
6086
by: Jose Perez | last post by:
Dear All, I have the following problem. I am passing an encrypted value on the querystring from one aspx to another. Originally I was outputing characters such as "+, /,..." (which caused...
2
3563
by: Bryan | last post by:
Apologies if this is a noob question, but I've been struggling with this for quite a while... I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string...
8
4178
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
6
53677
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...
4
1531
by: ThunderMusic | last post by:
Hi, I have to go from Byte() to String, do some processing then reconvert the String to byte() but using ascii format, not unicode. I currently use a stream to write the char()...
10
2659
by: Danny | last post by:
I am working on a project where I will receive xml documents from clients machines as a byte array. They will use the web browser navigate method to post the data to my ASP.NET page. I then pick up...
5
5949
by: jeremyje | last post by:
I'm writing some code that will convert a regular string to a byte for compression and then beable to convert that compressed string back into original form. Conceptually I have.... For...
6
3556
by: =?Utf-8?B?TWljaGFlbA==?= | last post by:
Hi, I need to create a formatted byte array for SMPP, e.g.: 00 00 00 21 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 is the length of the entire...
10
2869
by: ShadowLocke | last post by:
I'm looking for a better understanding of whats going on with the code i write. I have come across something that I thought I understood but its not working as expected. Its hard to explain so let me...
0
7242
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,...
0
7138
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
7423
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...
0
7510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5668
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,...
0
3225
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
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
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.