473,405 Members | 2,187 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,405 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 18 '05 #1
7 1622
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 18 '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 18 '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 18 '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 18 '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 18 '05 #6
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 18 '05 #7
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 18 '05 #8

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...
4
by: H Lee | last post by:
Hi, I'm an XML newbie, and not sure if this is the appropriate newsgroup to post my question, so feel free to suggest other newgroups where I should post this message if this is the case. I'm...
5
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...
0
agi2029
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,...
0
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...

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.