470,626 Members | 2,116 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,626 developers. It's quick & easy.

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 2822
"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 espaol : 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Robert Zierhofer | last post: by
8 posts views Thread by Tony Hedge | last post: by
14 posts views Thread by Jim Langston | last post: by
2 posts views Thread by Terry Chapman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.