473,659 Members | 2,626 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.W rite) from the
string (String.ToCharA rray), 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 3391
"ThunderMus ic" <NO.danlat.at.h otmail.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.En coding.<encodin g>.{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.Index Of("InfoToSearc h", 0) and it should find
"InfoToSeac h" 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...
"ThunderMus ic" <NO.danlat.at.h otmail.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.En coding.<encodin g>.{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.Enc oding.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.Enc oding.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.Defaul t is
characters being translated incorrectly...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"ThunderMus ic" <NO.danlat.at.h otmail.com.SPAM > wrote in message
news:%2******** *******@TK2MSFT NGP12.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.Index Of("InfoToSearc h", 0) and it should
find
| "InfoToSeac h" 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...
| > "ThunderMus ic" <NO.danlat.at.h otmail.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.En coding.<encodin g>.{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.Enc oding.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.Enc oding.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.Defaul t is
characters being translated incorrectly...

--
Hope this helps
Jay [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"ThunderMus ic" <NO.danlat.at.h otmail.com.SPAM > wrote in message
news:%2******** *******@TK2MSFT NGP12.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.Index Of("InfoToSearc h", 0) and it should
find
| "InfoToSeac h" 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...
| > "ThunderMus ic" <NO.danlat.at.h otmail.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.En coding.<encodin g>.{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
6092
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 problems), so I converted this byte array to Hex. When I come to read the string back into a byte array to decrypt it I always get an extra value, so myByte(40) becomes a length of 41 and I get an error relating to the length of the byte array. If I...
2
3579
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 that is displayed in a text box. Once displayed, the text will be copied, transmitted and then pasted (all manually by humans) into a second utility where the string must then be reverse-engineered into the *original* byte array. The byte array will...
8
4193
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, here's the code: ====================================== Dim textConverter As New ASCIIEncoding Dim sParam As String = "This is my cool param" Dim bytParam() As Byte 'load the byte array here...
6
53702
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 do I convert it to: dim myStr as string = "11,22,33,44"
4
1536
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() (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é...
10
2674
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 the byte array using the request object (XMLData=bytearray..). Can someone point me to an article that shows me how I can do this in ASP.NET, C#? Thanks Danny
5
5963
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 compression string ->(Unicode Conversion) byte -(Compression + Unicode Conversion) string
6
3566
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 message in octets, however the value is only in the 4 octet, is there someway I can format this into fixed width, a comparison would be
10
2897
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 show the code first.. private static extern int IntADsOpenObject(string path, string userName, string password, int flags,ref MyGuid iid, out object ppObject); struct MyGuid { public Int32...
0
8428
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
8339
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,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8629
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
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
6181
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
4176
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
2757
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

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.