473,287 Members | 2,682 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,287 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 2921
"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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.