How do I use System.Text.Enc oding.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. 8 8828
Adrian wrote:
How do I use System.Text.Enc oding.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
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
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:11******** **************@ j44g2000cwa.goo glegroups.com.. .
Adrian wrote:
How do I use System.Text.Enc oding.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.
"Marc Gravell" <ma**********@g mail.comwrote in message
news:uU******** ******@TK2MSFTN GP04.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.
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.AppendAllT ext() use UTF-8 by default, else
something like:
using(StreamWri ter writer = new StreamWriter(@" c:\myfile.txt", true, new
UTF8Encoding()) ) {
writer.WriteLin e("abc");
writer.WriteLin e("def");
}
Obviously you need to read them with UTF-8 compatible code, but this should
be very similar.
Does this answer the question?
Marc
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
"Marc Gravell" <ma**********@g mail.comwrote in message
news:uF******** ******@TK2MSFTN GP04.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.AppendAllT ext() use UTF-8 by default,
else
something like:
using(StreamWri ter writer = new StreamWriter(@" c:\myfile.txt", true, new
UTF8Encoding()) ) {
writer.WriteLin e("abc");
writer.WriteLin e("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.
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 = Encoding::UTF8->GetString(ByteGet)
String* E = Encoding::UTF8->GetString(ByteGetH)
if(E==D
|
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 the encoding they want and I'll do a pretty good job of converting. Basically, I take a string as input, write it to a byte array MemoryStream and then...
|
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? Say, I have different language OS (Win2000
Server), does System.Text.Encoding.Default.CodePage always return same value
under different OS?
...
|
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 was.
Here is some real simple console code. It seems like umlauts are not in
ASCII, but they are.
StreamWriter swExport = new...
|
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 perfectly, but not
when sending to DOS:
Private Function bytearray2string(ByVal input As Byte()) As String
Dim output As String
| |
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) ?
|
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 German characters.
1. When I use StreamReader(System.String filepath) without specifying an
encoding method, the German characters such as Ä are...
|
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 to understand
why.
the object 's' is a Mentalis.org component that, for all purposes here,
is a System.Net.Socket. the line I commented out is...
|
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...
|
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. ...
|
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...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |