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

System.Text.Encoding.Default question

How do I use System.Text.Encoding.Default
in conjunction with "append"?
The objective being not to get into all sorts of
problems with special ASCII characters
like é etc.

Many thanks,
Adrian.
Nov 21 '06 #1
8 8805
Adrian wrote:
How do I use System.Text.Encoding.Default
in conjunction with "append"?
In what context?
The objective being not to get into all sorts of
problems with special ASCII characters
like é etc.
Well, the first thing to understand is that that isn't an ASCII
character.

It would really help if you could explain what you're trying to do,
what kind of application you're writing etc.

Jon

Nov 21 '06 #2
ASCII only defines the first 128 symbols, which does not include é;

From your post, it isn't entirely sure if you are trying to exclude é from
the source, or handle it; it the latter, you can't using ASCII, which is why
encodings exist in the first place. Note that the "default" encoding is
(IIRC) only "default" on your system; in a different config something else
may be the default, and you could start seeing the wrong characters.
Either you need to agree on (or transmit separately) a specific codepage, or
you need to use a more versatile encoding such as UTF-8. Note that UTF-8 is
compatible with ASCII as long as you stay within the 128 ASCII characters.

If you clarify what exactly you want to do, somebody can probably give a
more complete answer

Marc
Nov 21 '06 #3
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
Adrian wrote:
How do I use System.Text.Encoding.Default
in conjunction with "append"?
In what context?
The objective being not to get into all sorts of
problems with special ASCII characters
like é etc.
Well, the first thing to understand is that that isn't an ASCII
character.

It would really help if you could explain what you're trying to do,
what kind of application you're writing etc.

Jon
*********************
Thank you for reply. I received the same reply (in content)
from another respondent and will explain in my reaction
to him.

Regards,
Adrian.
Nov 21 '06 #4
"Marc Gravell" <ma**********@gmail.comwrote in message
news:uU**************@TK2MSFTNGP04.phx.gbl...
ASCII only defines the first 128 symbols, which does not include é;

From your post, it isn't entirely sure if you are trying to exclude é from
the source, or handle it; it the latter, you can't using ASCII, which is
why
encodings exist in the first place. Note that the "default" encoding is
(IIRC) only "default" on your system; in a different config something else
may be the default, and you could start seeing the wrong characters.
Either you need to agree on (or transmit separately) a specific codepage,
or
you need to use a more versatile encoding such as UTF-8. Note that UTF-8
is
compatible with ASCII as long as you stay within the 128 ASCII characters.

If you clarify what exactly you want to do, somebody can probably give a
more complete answer

Marc

*******************************
PROBLEM DESCRIPTION
*******************************
In an application I create text. For it I have
written a spell check module in which I
compare words from the text with words
from the vocabulary. If the vocabulary
does not contain a word, that word is
added to the vocabulary upon the request
of the user. Problems arise if the word
the user adds contains characters like é,
à, ë, etc. Their representation in the
list of vocabulary words, which is a txt
file, is with 'funnies', presumably because
the txt format cannot handle characters outside
of the limited range of ASCII characters.
*******************************
Many thanks in advance for your help.

Adrian.
Nov 21 '06 #5
Well, people get very touchy over the squiggles etc in spelling, so IMO the
correct approach here is to handle the non-ASCII data. To avoid problems, I
would recommend simply explicitely using UTF-8.

I believe File.Append() and File.AppendAllText() use UTF-8 by default, else
something like:

using(StreamWriter writer = new StreamWriter(@"c:\myfile.txt",true, new
UTF8Encoding())) {
writer.WriteLine("abc");
writer.WriteLine("def");
}

Obviously you need to read them with UTF-8 compatible code, but this should
be very similar.
Does this answer the question?

Marc
Nov 21 '06 #6
Problems arise if the word
the user adds contains characters like é,
à, ë, etc. Their representation in the
list of vocabulary words, which is a txt
file, is with 'funnies', presumably because
the txt format cannot handle characters outside
of the limited range of ASCII characters.
txt isn't really a "format" as such - it certainly doesn't specify
which encoding to use.

I suggest (like Mark did) that you both read and write the vocabulary
file using UTF-8.

Jon

Nov 21 '06 #7
"Marc Gravell" <ma**********@gmail.comwrote in message
news:uF**************@TK2MSFTNGP04.phx.gbl...
Well, people get very touchy over the squiggles etc in spelling, so IMO
the
correct approach here is to handle the non-ASCII data. To avoid problems,
I
would recommend simply explicitely using UTF-8.

I believe File.Append() and File.AppendAllText() use UTF-8 by default,
else
something like:

using(StreamWriter writer = new StreamWriter(@"c:\myfile.txt",true, new
UTF8Encoding())) {
writer.WriteLine("abc");
writer.WriteLine("def");
}

Obviously you need to read them with UTF-8 compatible code, but this
should
be very similar.
Does this answer the question?

Marc

********************************
Thank you, yes, I expect it will. I will
give it a try and see where that leads me.

Many thanks again,
Adrian.
Nov 21 '06 #8
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Problems arise if the word
the user adds contains characters like é,
à, ë, etc. Their representation in the
list of vocabulary words, which is a txt
file, is with 'funnies', presumably because
the txt format cannot handle characters outside
of the limited range of ASCII characters.
txt isn't really a "format" as such - it certainly doesn't specify
which encoding to use.

I suggest (like Mark did) that you both read and write the vocabulary
file using UTF-8.

Jon
******************************
Yes, that is what Marc suggested as well.
Thank you Jon.

Regards,
Adrian.
Nov 21 '06 #9

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

Similar topics

1
by: Shreyash Patel | last post by:
The E==D fails for some reason. Can enyone tell me why String* A = S"ABC" String* C = S"ABC" Byte ByteGet = Encoding::UTF8->GetBytes(A) Byte ByteGetH = Encoding::UTF8->GetBytes(C) String* D =...
2
by: Mark | last post by:
Sorry about the last... Anyway, here's the question: I've been working on some C# routines to process strings in and out of various encodings. The hope is that I can just let the user type in...
1
by: Hardy Wang | last post by:
Hi, Guys I am currently working with a multi-language project, and I have a question, is System.Text.Encoding.Default related to machine (locale English, French, Chinese and etc) or independent?...
3
by: Chris Auer | last post by:
I am trying to take in ASCII documents and convert them into ANSI for a customer in Germany. But every file I process turns umlauts and other german characters into something other then what it...
4
by: I.Charitopoulos | last post by:
The reason I want to do so, is that I am sending to DOS and I am pretty certain that it will not work. Everything I've tried so far hasnt. In my test environment (Windows to Windows) this works...
1
by: Emilio | last post by:
Question about Dim data As () = System.Text.Encoding.ASCII.GetBytes(message) Would it be the same to write: Dim data() As Byte = System.Text.Encoding.ASCII.GetBytes(message) ?
4
by: George | last post by:
Hi, I am puzzled by the following and seeking some assistance to help me understand what happened. I have very limited encoding knowledge. Our SAP system writes out a text file which includes...
4
by: A_StClaire_ | last post by:
hi, I am using the following code to download multiple file types from a server. .txt files transfer fine. however Word .doc files come through garbled and I don't know enough about encoding...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.