473,830 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems writing a pound (sterling) sign to a file

Using the following code I am trying to write to a text file. I keep
getting "£"

All I want is "£"

Any Ideas?

using System;

using System.IO;

using System.Text;

public class TextToFile

{

private const string FILE_NAME = "MyFile.txt ";

public static void Main(String[] args)

{

if (File.Exists(FI LE_NAME))

{

Console.WriteLi ne("{0} already exists.", FILE_NAME);

return;

}
StreamWriter sr = File.AppendText (FILE_NAME);

sr.WriteLine ("£");

sr.Close();

}

}

Nov 15 '05 #1
2 3818
Colby,

Instead of calling the AppendText method, create the StreamWriter
instance yourself, using a FileStream instance, and pass the encoding to the
StreamWriter that the character is a part of. The AppendText method makes
some assumptions about the encoding which is probably what is causing your
problem.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Colby" <co************ *********@yahoo .com> wrote in message
news:Oc******** ******@TK2MSFTN GP11.phx.gbl...
Using the following code I am trying to write to a text file. I keep
getting "£"

All I want is "£"

Any Ideas?

using System;

using System.IO;

using System.Text;

public class TextToFile

{

private const string FILE_NAME = "MyFile.txt ";

public static void Main(String[] args)

{

if (File.Exists(FI LE_NAME))

{

Console.WriteLi ne("{0} already exists.", FILE_NAME);

return;

}
StreamWriter sr = File.AppendText (FILE_NAME);

sr.WriteLine ("£");

sr.Close();

}

}


Nov 15 '05 #2
Colby <co************ *********@yahoo .com> wrote:
Using the following code I am trying to write to a text file. I keep
getting "£"


No, you're getting "£" in UTF-8 (I believe), which is the default
encoding for StreamWriter. Now, what encoding do you *want* your stream
to be in?

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

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

Similar topics

4
25951
by: Robert Zierhofer | last post by:
hi there, it seems as if i can´t convert the euro and pound sign to their html equivalents. i tried eregi_replace("€", "&euro;", $haystack); eregi_replace("£", "&pound;", $haystack); as well as
7
3407
by: LRW | last post by:
Below I'll paste my CSS and the HTML in question. But what's happening is, I'm trying to establish a link behavior for a class that's separate from the normal link class. I've established a: 's with no underline and then an underline for hover...but oddly, only ONE link will actually show the underline on hover. All the rest, even with the same HTML, won't pop up an underline. I just don't get it! If I could get any advice I'd really...
4
16816
by: ben | last post by:
Hi all, I have a simple PHP page that takes values from a form and puts them in a database (MySQL). The code is in a file test.php, which I have typed in at the bottom of this post (please excuse any typos). This page is not a production page - I created it just to try and solve the £ sign problem I am having. When I put the pound sign (£) into the input box and submit the form,
5
7976
by: Waldy | last post by:
Hi there, I am using the .Net XML Serialization classes to create XML strings. This has been working fine up until the point that one of the strings contained a pound sterling symbol. The application that is processing the output complains about the character. Both the strings and the application are using UTF-8. If you view the text in Notepad the pound symbol looks fine, but if you view the hex, there is a character preceding the...
1
1139
by: chauc3r | last post by:
I'm having problems writing to a text file. Basically it refuses to write anything. The file is created. At the appropiate times it goes into the correct if statements (I have verified this using msgboxes). Any idea why it wouldnt be writing anything? Do Until (objFacilitySht.Cells(row, cboAPName.Text).Value = "") Dim fsStream As New FileStream(txtSaveto.Text & "\" & objFacilitySht.Cells(row, cboAPName.Text).Value & ".txt",...
2
6706
by: junk | last post by:
Hi, Sorry if this has been asked before, and apologise if this is the wrong NG. I am using PHP 5.0.5 and Apache 2.0.54 in a Win2k environment. Lately I have been playng with RSS feeds. I managed to get "lastRSS" which is a simple RSS parser.
9
2941
by: musosdev | last post by:
I'm having trouble writing £ (pound sign) to a file from my asp.net app. I've tried.. StreamWriter.WriteLine("£") - and - StreamWriter.WriteLine(Convert.ToChar(156).ToString()) but neither give me the £ sign - they give me weird characters! I think 156 is the char code for £ ..?!
20
2932
by: Chris Withers | last post by:
Hi All, The following piece of code is giving me issues: from email.Charset import Charset,QP from email.MIMEText import MIMEText charset = Charset('utf-8') charset.body_encoding = QP msg = MIMEText( u'Some text with chars that need encoding: \xa3',
1
1369
by: Spondishy | last post by:
Hi, I'm using SQL Server session state, but the user I'm using to access this has a pound sign (£) in the password. This works locally, but not on the server stating that the web.config contains invalid characters. I've copied the machine.config from the server to my machine, but this still works. Can anyone point me to what the problem could be. BTW I can't change the password to something without a £ sign. <sessionState...
0
9642
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
10489
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...
1
10525
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
9314
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
7746
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
5617
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
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
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.