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

Encoding.Default and Encoding.UTF8

Hi,
I have following code:
Encoding mode; // Encoding.Default or Encoding.UTF8
FileStream sb = new FileStream(fullPathAndFileName, FileMode.Create);
StreamWriter sw = new StreamWriter(sb, mode);
sw.Write(textContent);
sw.Close();

My question is under what situation, the saved files are different by
calling Encoding.Default and Encoding.UTF8.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 16 '05 #1
5 3600
Hardy Wang <ha********@marketrend.com> wrote:
I have following code:
Encoding mode; // Encoding.Default or Encoding.UTF8
FileStream sb = new FileStream(fullPathAndFileName, FileMode.Create);
StreamWriter sw = new StreamWriter(sb, mode);
sw.Write(textContent);
sw.Close();

My question is under what situation, the saved files are different by
calling Encoding.Default and Encoding.UTF8.


They'll almost certainly be different for any string containing non-
ASCII characters. They're likely to be the same for any string
containing solely ASCII characters.

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
Nov 16 '05 #2
Thanks,
Anybody knows are there any characters in French and Spanish greater than
128 ASCII code?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Hardy Wang <ha********@marketrend.com> wrote:
I have following code:
Encoding mode; // Encoding.Default or Encoding.UTF8
FileStream sb = new FileStream(fullPathAndFileName, FileMode.Create);
StreamWriter sw = new StreamWriter(sb, mode);
sw.Write(textContent);
sw.Close();

My question is under what situation, the saved files are different by
calling Encoding.Default and Encoding.UTF8.


They'll almost certainly be different for any string containing non-
ASCII characters. They're likely to be the same for any string
containing solely ASCII characters.

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

Nov 16 '05 #3
Hardy Wang <ha********@marketrend.com> wrote:
Anybody knows are there any characters in French and Spanish greater than
128 ASCII code?


There are no such thing as ASCII values above 127. What did you mean,
exactly?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Let me make it clear, I am just wandering if there are any characters in
French and Spanish non ASCII character.

What I would like to know is, if there are such characters, by using
Encoding.Default (US English or Canada English as Win2000's locale) to save
to a text file, will these characters be lost?

Thanks!

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Hardy Wang <ha********@marketrend.com> wrote:
Anybody knows are there any characters in French and Spanish greater than 128 ASCII code?


There are no such thing as ASCII values above 127. What did you mean,
exactly?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Hardy Wang <ha********@marketrend.com> wrote:
Let me make it clear, I am just wandering if there are any characters in
French and Spanish non ASCII character.
Certainly - any accented characters, to start with.
What I would like to know is, if there are such characters, by using
Encoding.Default (US English or Canada English as Win2000's locale) to save
to a text file, will these characters be lost?


Possibly. However, there are various characters in Encoding.Default
which *aren't* in ASCII, and which won't be lost.

I'd strongly recommend using UTF-8 if you have the opportunity,
however.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

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

Similar topics

10
by: Achim Domma | last post by:
Hi, I read a webpage via urllib2. The result of the 'read' call is of type 'str'. This string can be written to disc via file('out.html','w').write(html). Then I write the string into a...
4
by: Majed | last post by:
Hi , all I'm trying to write unicode to a file for another app (not developed with vs2003) to read it. I used StreamWriter with unicode encoding.but I was surprised that the streamwriter adds FFFE...
7
by: Hardy Wang | last post by:
Hi, I have following code: Encoding mode; // Encoding.Default or Encoding.UTF8 FileStream sb = new FileStream(fullPathAndFileName, FileMode.Create); StreamWriter sw = new StreamWriter(sb, mode);...
2
by: Jim Lawton | last post by:
Hi, ..net c# httphandler straight html form at browser. GBP pound sign problem (I know I know - I *can* decode it, but I've got to understand what and why I should be doing stuff) I am...
7
by: MrNobody | last post by:
I am having alot of difficulty with text files in .NET when they have special characters like í, ó, ç etc... When i read a text file with them and then write it back out it ignores all of...
19
by: Thomas W | last post by:
I'm getting really annoyed with python in regards to unicode/ascii-encoding problems. The string below is the encoding of the norwegian word "fødselsdag". I stored the string as "fødselsdag"...
8
by: MaxMax | last post by:
Is it possible to tell to the WebClient to use an "automatic" encoding when doing DownloadString? The encoding of the connection is written in the header, so the WebClient should be able to sense...
0
by: deloford | last post by:
Hi This is going to be a question for anyone who is an expert in C# Text Encoding. My situation is this: I have a Sybase database which is firing back ISO-8559 encoded strings. I am unable to...
1
by: arunairs | last post by:
Hi, After writing the £ (pound sterling) symbol to a file using StreamWriter using the default encoding UTF8, when I retrieve it the file symbol £ gets changed. But when I use Encoding.Default in...
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:
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...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
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
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.