473,395 Members | 1,815 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,395 software developers and data experts.

bytes to string conversion

GM
Hello,

I have incoming bytes from a tcp connection.
These bytes contain characters like é,ç,à,...

When I convert these bytes into a string using
----
Dim clientdata As String = System.Text.Encoding.ASCII.getstring(bytes)
----
I loose my special characters.
I've tried other encodings like
system.text.encoding.unicode.getstring(bytes), but this doesn't work.

Any ideas?
Nov 21 '05 #1
6 4401
GM,

Why not first start with "default" before you convert your input to 7bit
ASCII characters.

That will definitly remove all special characters.

Cor
Nov 21 '05 #2
GM
> Why not first start with "default" before you convert your input to 7bit
ASCII characters.

That will definitly remove all special characters.


Default also doesn't work (that was my first try)
Nov 21 '05 #3
GM
> ----
I loose my special characters.
I've tried other encodings like
system.text.encoding.unicode.getstring(bytes), but this doesn't work.

good: Louie düvaliéè
bad: Louie dvali,S

The client is a c++ program, the server is vb.net
Nov 21 '05 #4
"GM" <in*****@invalid.com> schrieb:
I have incoming bytes from a tcp connection.
These bytes contain characters like é,ç,à,...

When I convert these bytes into a string using
----
Dim clientdata As String = System.Text.Encoding.ASCII.getstring(bytes)
----
I loose my special characters.
ASCII is 7-bit only and does not contain these special characters
(<URL:http://www.asciitable.com/>).
I've tried other encodings like
system.text.encoding.unicode.getstring(bytes), but this doesn't work.


What encoding is used to encode the data before sending? You'll have to use
the same encoding to decode the string from the byte array.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
I've managed to achieve something like this as folows:

let's day I've got a byte-array with values: {200, 201, 202}, in chars: È,
É, Ê. If you try to convert it straightaway to a Unicode string it fails.
This is because Unicode uses 2 bytes for 1 character. So for each character
I've inserted a seccond byte with the value 0. You can easily achieve this
in a For...Next loop.

So now I've got a byte() with values: {200, 0, 201, 0, 202, 0}. If you
insert this array into the function:
System.Text.UnicodeEncoding.Unicode.GetString() it results in the correct
string.

HTH,
Friso Wiskerke
"GM" <in*****@invalid.com> wrote in message
news:Ov**************@TK2MSFTNGP11.phx.gbl...
----
I loose my special characters.
I've tried other encodings like
system.text.encoding.unicode.getstring(bytes), but this doesn't work.

good: Louie düvaliéè
bad: Louie dvali,S

The client is a c++ program, the server is vb.net

Nov 21 '05 #6
GM,

You can play a little with the different code tables, you can see what is
your computer in the language culture settings of that.

Than you can use a codeset
System.Text.Encoding.GetEncoding(437).GetBytes(Str .ReadToEnd)

This one is an old DOS one used in by instance the US, UK and NL.

The normal windows one is 1252

I hope this helps

Cor

Nov 21 '05 #7

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

Similar topics

5
by: Jonathan Halterman | last post by:
I have a pointer to a buffer of bytes that I receive from a tcp stream that I would like to place into some kind of stream that can I can then use to serialize the data into into individual...
17
by: Karl Ebener | last post by:
Hi! I asked a similar question before but then changed everything to using char-Arrays instead of the string class, but I would rather not do this again. So, does anyone know of a...
0
by: Christophe Elek | last post by:
Ok, I am completly at lost :) in both cases (my Yenc and zip utilities) i try to do the following 1) get a String 2) transform in byte 3) so some computation (either adding value to the byte...
5
by: Jazper | last post by:
hi can anybody explain that to me: i did the following: - 1. input of char 244 ("ô") into string - 2. convert to getbytes - 3. convert back to string char 244 changed to char 63 ("?")...
2
by: SK | last post by:
Hi, I am not able to convert the response stream from HttpWebResponse into bytes properly. Here is the relevent code - HttpWebResponse response = (HttpWebResponse)request.GetResponse (); ...
3
by: dermot | last post by:
None of the Converter tyeps (eg ASCIIEncoding )let you convert between string and 8-bit bytes (0-255). It took me a long time to find there is a way, well, at least 2 ways.....here is the way to...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
8
by: sexauthor | last post by:
I'm converting a VB6 application over that called a 3rd party DLL with specific data structures. The VB6 code defined custom types for those data structures (ie: one with the specific data types,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
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,...
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...

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.