473,800 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UTF encoding and StreamWriter

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.Defaul t 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,

Arun

Jun 27 '08 #1
1 2511
Hi Arun,

You are not saving and reading the file using the same Encoding.

If you do not specify encoding the StreamWriter/Reader will default to UTF8,
but other applications often default to the code page used by your current
locale, Encoding.Defaul t (ANSI). For instance, Notepad uses ANSI encoding if
not told otherwise.

Check your reading/writing code. If both reading and writing uses UTF8, do
other parts of your program, or other applications, create the file in
question?

--
Happy Coding!
Morten Wennevik [C# MVP]
"ar******@gmail .com" wrote:
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.Defaul t 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,

Arun

Jun 27 '08 #2

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

Similar topics

4
2466
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
8
6119
by: timtos | last post by:
I want to save text in a file and after that I want to display this textfile using the internet explorer. If I am displaying "html text" everything is fine but if I want to display plain text all characters from the extended ascii are looking weird - are not properly encoded! Using the options in View -> Encoding -> ... in the internet explorer I can switch to another encoding and it is displayed correct. With the same way, I can make...
3
2712
by: ZoombyWoof | last post by:
Hi all. I have a c# app that sometimes writes to a textfile. Sometimes the text contains the swedish letters åäö. In the app these letters look ok, but when StreamWriter has written them to the file they look like shit. Some encoding mismatch is happening here I suspect, but I cant find it. I run English version of XP with swedish regional settings everywhere I can find them :-). Any hints would be much appreciated. Thanx
6
31083
by: kinekine | last post by:
Hello, i have a big problem with my email component, because each time i write the generated message directly to the spooler, the streamwriter will write in Unicode. The file starts with a FF FE and is double byte. This is a problem because when a mail server like QMAIL receive the message, will reject for malformed LF.
11
31736
by: LucaJonny | last post by:
Hi, I've got a problem using StreamReader in VB.NET. I try to read a txt file that contains extended characters and theese are removed from the line that is being read. I've read a lot of articles about ANSI encoding like this http://support.microsoft.com/default.aspx?scid=kb;en-us;889835 but System.Text.Encoding.Default don't work!!
2
5609
by: lprisr | last post by:
Hi, I have double byte characters in the content that I am returning using Web Services. However, the encoding in the xml file returned by Web Services is utf-8 and I am unable to read the content, not even by changing browser encoding setting to the appropriate one. I implemented SoapExtension (called EncodingExtension) to rewrite the xml to change the encoding="utf-8" to encoding="windows-1252" in BeforeDeserialize SoapMessage...
4
5564
by: Bob | last post by:
Hi Need to produce a Doc with no encoding info. Is there anyway of doing this? Thanks Bob i.e. <?xml version=\"1.0\" ?>
3
20259
by: Diego F. | last post by:
Hi. I'm using that code: If File.Exists(Ls_NombreFichero) = False Then sw = File.CreateText(Ls_NombreFichero) Else sw = File.AppendText(Ls_NombreFichero) End If I need to change the encoding, as utf-8 is not the one I can use. How can I change it? Encoding property is read only and I don't know how to use the
9
1762
by: Tomasz Toczyski | last post by:
My locale is set to UTF-8. The command: python -c "print u'\u03A9'" gives me the desired result and doesn't produce any error. But when I want to redirect the output to a file I invoke: python -c "print u'\u03A9'" file.txt I get an error: File "<string>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\u03a9' in
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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
10505
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
10033
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...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
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
6811
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();...
1
4149
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
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.