473,395 Members | 2,253 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,395 software developers and data experts.

writing £ sign to file

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).ToStrin g())

but neither give me the £ sign - they give me weird characters! I think 156
is the char code for £ ..?!

I've got my culture and uiCulture set to "en-GB" in my webconfig. Not sure
what else to try. Please help!

Cheers
Dan
May 12 '06 #1
9 2923
"musosdev" <mu*******@community.nospam> wrote in message
news:95**********************************@microsof t.com...
but neither give me the £ sign - they give me weird characters! I think
156
is the char code for £ ..?!


Try 163 instead...
May 12 '06 #2
nope, that gives me... £

not quite sure why im getting the  !?

"Mark Rae" wrote:
"musosdev" <mu*******@community.nospam> wrote in message
news:95**********************************@microsof t.com...
but neither give me the £ sign - they give me weird characters! I think
156
is the char code for £ ..?!


Try 163 instead...

May 12 '06 #3
I believe that, that character is a double byte character. Which means
if you read a text file written in double byte, or contains a double
byte charater from a text reader that doesn't support double bytes -
you will get some wierd display characters.

This is only an oppinion however.

-Rick

May 12 '06 #4
okay so... how do i fix it?! :)

"Rick" wrote:
I believe that, that character is a double byte character. Which means
if you read a text file written in double byte, or contains a double
byte charater from a text reader that doesn't support double bytes -
you will get some wierd display characters.

This is only an oppinion however.

-Rick

May 12 '06 #5


musosdev wrote:
I'm having trouble writing £ (pound sign) to a file from my asp.net app. but neither give me the £ sign - they give me weird characters!


What encoding should the file have? It sounds like you are writing the
file with one encoding but whatever application reads the file uses a
different encoding (or rather decoding then).

So decide whether you want to write the file as Windows-1252 or
ISO-8859-1 or UTF-8 for example and then use the intended encoding e.g.
using (StreamWriter streamWriter = new
StreamWriter(Server.MapPath("file.txt"), false, Encoding.UTF8)) {
streamWriter.Write("£");
}

Of course if you then want anyone on the web to properly read that file
then make sure that the web server serves the file with a HTTP header
declaring the encoding.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 12 '06 #6
Thanks Martin,

How do I do the last bit? Is that something I have to do in IIS?
"Martin Honnen" wrote:


musosdev wrote:
I'm having trouble writing £ (pound sign) to a file from my asp.net app.

but neither give me the £ sign - they give me weird characters!


What encoding should the file have? It sounds like you are writing the
file with one encoding but whatever application reads the file uses a
different encoding (or rather decoding then).

So decide whether you want to write the file as Windows-1252 or
ISO-8859-1 or UTF-8 for example and then use the intended encoding e.g.
using (StreamWriter streamWriter = new
StreamWriter(Server.MapPath("file.txt"), false, Encoding.UTF8)) {
streamWriter.Write("£");
}

Of course if you then want anyone on the web to properly read that file
then make sure that the web server serves the file with a HTTP header
declaring the encoding.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

May 12 '06 #7


musosdev wrote:
How do I do the last bit? Is that something I have to do in IIS?


Preferably you would configure the web server to indicate the encoding
with a charset parameter e.g.
Content-Type: text/html; charset=Windows-1252
or
Content-Type: text/plain; charset=UTF-8

If it is a HTML document you write then you can also try to insert
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=Windows-1252">
in the HTML document, browsers will pick up the encoding from the
charset parameter then.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 13 '06 #8
If you're using UTF-8 or iso-8859-1 encoding, you can use

£

in the text and the pound sign ( £ ) will be written to the page.

You can also write it to a label :

<body>
£ <br/>
<asp:Label id="lblMessage" runat="server"/>£</asp:Label> <br />
</body>

To specify the encoding for an ASP.NET application, configure the desired encoding in web.config :

<globalization
requestEncoding="iso-8859-1"
responseEncoding="iso-8859-1"
fileEncoding="iso-8859-1"
/>

<globalization
requestEncoding="UTF-8"
responseEncoding="UTF-8"
fileEncoding="UTF-8"
/>

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"musosdev" <mu*******@community.nospam> wrote in message
news:7A**********************************@microsof t.com...
nope, that gives me... £

not quite sure why im getting the  !?

"Mark Rae" wrote:
"musosdev" <mu*******@community.nospam> wrote in message
news:95**********************************@microsof t.com...
> but neither give me the £ sign - they give me weird characters! I think
> 156
> is the char code for £ ..?!


Try 163 instead...

May 13 '06 #9
Hi Dan,

As for character's parsing and displaying, it is depend on charset/encoding
rather than culture. Also, 156 is apparently a non-ASCII char(larger than
128) so such char will has different codepoint in different
charset/encoding schema. So what's the charset you're using in your
application to parse text data? I've saw that the code seems contain the
"windows1252", I assumed that you're using this. Then, you should
explicitly use this encoding schema to parse byte to string or convert
string to byte stream. e.g:

================================
protected void Page_Load(object sender, EventArgs e)
{
Encoding enc = Encoding.GetEncoding("Windows-1252");
string txt = enc.GetString(new byte[] { 156 });

Response.Write("<br/>156: " + txt);
}
=========================================

Here are some other related tech articles:

http://www.codeproject.com/aspnet/En..._in_ASPNET.asp

http://samples.gotdotnet.com/quickst...eencoding.aspx

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 15 '06 #10

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

Similar topics

4
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...
1
by: sun | last post by:
In Javascript, I write to document.cookie, and retrieve it in server side. It's in a treenode control, when the node is expanded, I write document.cookie: if(subTree.style.display ==...
2
by: Colby | last post by:
Using the following code I am trying to write to a text file. I keep getting "£" All I want is "£" Any Ideas? using System;
8
by: Tony Hedge | last post by:
Hello, A .NET 1.1 web app... I create a hyperlink with a complete filename, and the target is for a new window to open. Right now the filenames are all PDF files. Everything works fine, the...
8
by: SP | last post by:
The following code crashes after I add the two nested FOR loops at the end, I am starting to learn about pointers and would like to understand what I'm doing wrong. I think the problem is the way...
1
by: buntyindia | last post by:
Hi , I am exporting files from my application. Files those are not supposed to be exported are of two types : 1.) Blank with Zero bytes 2.) Other one is in a format # #Mon Aug 13 14:33:02...
14
by: Jim Langston | last post by:
The output of the following program is: 1.#INF 1 But: 1.#INF 1.#INF was expected and desired. How can I read a value of infinity from a stream?
0
by: Prodian | last post by:
Im using NINI parser to read and write to an ini file. Everythings working fine, its reading and writing but lets say I read in these vaules: Test=1 Off=0 On=1 Test=1 Off=0 On=1
2
by: Terry Chapman | last post by:
I have a 2003 Access .mda add-in which I can sign using my Thawte digital certificate. I am now migrating this add-in to Access 2007 and when I try to add my Thawte digital signature Access 2007...
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:
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
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
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
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,...
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,...

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.