473,659 Members | 3,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Text.Enc oding.Default question

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.
Nov 21 '06 #1
8 8832
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

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.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.
Nov 21 '06 #4
"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.
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.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
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**********@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.
Nov 21 '06 #8
"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.
Nov 21 '06 #9

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

Similar topics

1
1266
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
2
395
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 get the bytes of the conversion out. The oddity in my question is that when I use...
1
1076
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? Thanks! --
3
9682
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 StreamWriter("C:\\MyDocuments\\In Progress\\IIR\\OUT.txt",false,System.Text.Encoding.ASCII); swExport.WriteLine("Ö");
4
6697
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
1
9769
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
34149
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 lost when I do a ReadLine()
4
2034
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 one that hard-codes the encoding to 'ASCII' which I assume would only hurt me.
0
8335
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
8747
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
8627
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...
1
6179
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
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
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
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.