473,406 Members | 2,849 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,406 software developers and data experts.

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 1525
"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

3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
2
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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
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...
0
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
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...

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.