I'm having a problem with encoding a string... here's my code:
byte[] s = System.Text.Encoding.ASCII.GetBytes(FieldContent);
Now, this works fine, as long as there are no bytes that are over 128, for
example, a 0x99 byte turns out as 0x3f byte.
I know that ASCII is just 7 bits, but i tried the other encoding formats,
and they didn't get me what i needed... UTF7 did the same thing as ASCII,
UTF8 gave 0xC299 for each 0x99 byte, and UNICODE gave good results, but in
unicode format.
What am i doing wrong?
Miki 11 3545
Well, i managed to find a solution of some sort:
System.Text.Encoding e = System.Text.Encoding.GetEncoding("iso-8859-1");
output = BitConverter.ToString(e.GetBytes(FieldContent)).Re place("-"," ");
Is there something equivalent to the iso-8859-1 codepage?
Miki
Well, i managed to find a solution of some sort:
System.Text.Encoding e = System.Text.Encoding.GetEncoding("iso-8859-1");
output = BitConverter.ToString(e.GetBytes(FieldContent)).Re place("-"," ");
Is there something equivalent to the iso-8859-1 codepage?
Miki
> Is there something equivalent to the iso-8859-1 codepage?
1252 is the MS equivalent (it is in fact iso-8859-1 with some extras)
--
Mihai
-------------------------
Replace _year_ with _ to get the real email
> Is there something equivalent to the iso-8859-1 codepage?
1252 is the MS equivalent (it is in fact iso-8859-1 with some extras)
--
Mihai
-------------------------
Replace _year_ with _ to get the real email
Miki Watts <mi*****@netvision.net.il> wrote: I'm having a problem with encoding a string... here's my code:
byte[] s = System.Text.Encoding.ASCII.GetBytes(FieldContent);
Now, this works fine, as long as there are no bytes that are over 128, for example, a 0x99 byte turns out as 0x3f byte. I know that ASCII is just 7 bits, but i tried the other encoding formats, and they didn't get me what i needed... UTF7 did the same thing as ASCII, UTF8 gave 0xC299 for each 0x99 byte, and UNICODE gave good results, but in unicode format.
What am i doing wrong?
Nothing. What do you think it's doing wrong? It's doing exactly what it
should be - it's encoding your text in the various different ways,
depending on the encoding type used.
See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Miki Watts <mi*****@netvision.net.il> wrote: I'm having a problem with encoding a string... here's my code:
byte[] s = System.Text.Encoding.ASCII.GetBytes(FieldContent);
Now, this works fine, as long as there are no bytes that are over 128, for example, a 0x99 byte turns out as 0x3f byte. I know that ASCII is just 7 bits, but i tried the other encoding formats, and they didn't get me what i needed... UTF7 did the same thing as ASCII, UTF8 gave 0xC299 for each 0x99 byte, and UNICODE gave good results, but in unicode format.
What am i doing wrong?
Nothing. What do you think it's doing wrong? It's doing exactly what it
should be - it's encoding your text in the various different ways,
depending on the encoding type used.
See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Mihai N. <nm**************@yahoo.com> wrote: Is there something equivalent to the iso-8859-1 codepage? 1252 is the MS equivalent (it is in fact iso-8859-1 with some extras)
Sort of - using the 8859-1 code page, you'll actually end up with bytes
effectively being "passed through", even if they shouldn't really be.
(I'm talking about characters 128-139 IIRC.) Code page 1252 has
entirely different characters in that range (the extras you mean).
If the OP wants 8859-1, he can just use the form he's already shown, or
ask for codepage number 28591. It's not a good idea though, if he's
basically using it to treat a string as sequence of bytes instead of
chars.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Mihai N. <nm**************@yahoo.com> wrote: Is there something equivalent to the iso-8859-1 codepage? 1252 is the MS equivalent (it is in fact iso-8859-1 with some extras)
Sort of - using the 8859-1 code page, you'll actually end up with bytes
effectively being "passed through", even if they shouldn't really be.
(I'm talking about characters 128-139 IIRC.) Code page 1252 has
entirely different characters in that range (the extras you mean).
If the OP wants 8859-1, he can just use the form he's already shown, or
ask for codepage number 28591. It's not a good idea though, if he's
basically using it to treat a string as sequence of bytes instead of
chars.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
> If the OP wants 8859-1, he can just use the form he's already shown, or ask for codepage number 28591. It's not a good idea though, if he's basically using it to treat a string as sequence of bytes instead of chars.
well, yes, basically, that is what i want to do, i want a string (i.e.
dynamic resize) that contains the exact bytes that i want, without
interpetation or encoding. I haven't found any other construct that can do
this for me though. (byte[] should be what i need, but it's not dynamic).
Miki Watts <mi*****@netvision.net.il> wrote: If the OP wants 8859-1, he can just use the form he's already shown, or ask for codepage number 28591. It's not a good idea though, if he's basically using it to treat a string as sequence of bytes instead of chars. well, yes, basically, that is what i want to do, i want a string (i.e. dynamic resize) that contains the exact bytes that i want
Strings don't contain bytes. They contain characters. You shouldn't use
them for binary data - that's not what they're designed for.
without interpetation or encoding. I haven't found any other construct that can do this for me though. (byte[] should be what i need, but it's not dynamic).
String itself isn't dynamic either - once created, a string is fixed.
It just has methods to make it easy to create a new string with (say)
the value of two strings concatenated.
I suspect that MemoryStream might be helpful to you though.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
> I suspect that MemoryStream might be helpful to you though.
ok, thanks. I'll check it out. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lkrubner |
last post by:
Last year I asked a bunch of questions about character encoding on this
newsgroup. All the answers came down to using ord() in creative ways to
try to make guesses about multi-byte characters. I...
|
by: Sylvain Thenault |
last post by:
Hi there !
I've noticed the following problem with python >= 2.3 (actually 2.3.4 and
2.4):
syt@musca:test$ python
Python 2.3.4 (#2, Sep 24 2004, 08:39:09)
on linux2
Type "help", "copyright",...
|
by: Neil Schemenauer |
last post by:
The title is perhaps a little too grandiose but it's the best I
could think of. The change is really not large. Personally, I
would be happy enough if only %s was changed and the built-in was...
|
by: michael.casey |
last post by:
The purpose of this post is to obtain the communities opinion of the
usefulness, efficiency, and most importantly the correctness of this
small piece of code. I thank everyone in advance for your...
|
by: Miki Watts |
last post by:
I'm having a problem with encoding a string... here's my code:
byte s = System.Text.Encoding.ASCII.GetBytes(FieldContent);
Now, this works fine, as long as there are no bytes that are over 128,...
|
by: Mark |
last post by:
I've run a few simple tests looking at how query string encoding/decoding gets handled in asp.net, and it seems like the situation is even messier than it was in asp... Can't say I think much of the...
|
by: Ger |
last post by:
I have not been able to find a simple, straight forward Unicode to ASCII
string conversion function in VB.Net.
Is that because such a function does not exists or do I overlook it?
I found...
|
by: Richard Schulman |
last post by:
The following program fragment works correctly with an ascii input
file.
But the file I actually want to process is Unicode (utf-16 encoding).
The file must be Unicode rather than ASCII or...
|
by: Holger Joukl |
last post by:
Hi there,
I consider the behaviour of unicode() inconvenient wrt to conversion of
non-string
arguments.
While you can do:
u'17.3'
you cannot do:
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
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,...
|
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...
|
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,...
|
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...
| |