473,651 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encoding.Defaul t and Encoding.UTF8

Hi,
I have following code:
Encoding mode; // Encoding.Defaul t or Encoding.UTF8
FileStream sb = new FileStream(full PathAndFileName , FileMode.Create );
StreamWriter sw = new StreamWriter(sb , mode);
sw.Write(textCo ntent);
sw.Close();

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

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 16 '05 #1
5 3654
Hardy Wang <ha********@mar ketrend.com> wrote:
I have following code:
Encoding mode; // Encoding.Defaul t or Encoding.UTF8
FileStream sb = new FileStream(full PathAndFileName , FileMode.Create );
StreamWriter sw = new StreamWriter(sb , mode);
sw.Write(textCo ntent);
sw.Close();

My question is under what situation, the saved files are different by
calling Encoding.Defaul t 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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Hardy Wang <ha********@mar ketrend.com> wrote:
I have following code:
Encoding mode; // Encoding.Defaul t or Encoding.UTF8
FileStream sb = new FileStream(full PathAndFileName , FileMode.Create );
StreamWriter sw = new StreamWriter(sb , mode);
sw.Write(textCo ntent);
sw.Close();

My question is under what situation, the saved files are different by
calling Encoding.Defaul t 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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Hardy Wang <ha********@mar ketrend.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.co m>
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.Defaul t (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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Hardy Wang <ha********@mar ketrend.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Hardy Wang <ha********@mar ketrend.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.Defaul t (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.Defaul t
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.co m>
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
4974
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 Memofield in an Access database, using adodbapi. If I read the text back I get a unicode string, which can not written to disc via file(...) due to encoding problems. How do I have to decode the unicode string to get my original data back?
4
2454
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 to the start of the file,which stopes the other app from reading it!! any idea how to stope it frome doing that,do I have to use another class #####writer that supports unicode? help me Please! Thanks
7
1637
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); sw.Write(textContent); sw.Close(); My question is under what situation, the saved files are different by calling Encoding.Default and Encoding.UTF8.
2
2627
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 uploading text data from a form. This data is either directly input into a textarea, or is a file stream originating from a .txt file, (or other basic text file (like off Mac or Unix - of course I don't necessarily know at present it's
7
5775
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 those characters completely. I tried all the encoding types and it seems only Encoding.Default does it right... but it sounds dangerous... can I rely on Encoding.Default behaving like this for all other machines?
19
3322
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" but somewhere in my code it got translated into the mess above and I cannot get the original string back. It cannot be printed in the console or written a plain text-file. I've tried to convert it using
8
24528
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 it, but I wasn't able to find the option. I can only use a fixed Encoding (UTF8 for example) and hope the site use it. --- bye
0
5056
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 get the db to translate to UTF-8 for non technical reasons. So I have a string coming back with the character œ (ISO value 156). this character appears in .NET as a box character because 156 is not a valid Unicode character value. I have been...
1
2504
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 the StreamWriter, I am able to retrieve the symbol without any issue. Can you tell me why this is so? Microsoft recommend using UTF8 for encoding, but it does not seem to work in this case. thanks,
0
8278
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
8807
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...
1
8466
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8584
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
6158
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
5615
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
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1588
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.