473,803 Members | 3,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

writing £ sign to file

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

StreamWriter.Wr iteLine("£")
- and -
StreamWriter.Wr iteLine(Convert .ToChar(156).To String())

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 2940
"musosdev" <mu*******@comm unity.nospam> wrote in message
news:95******** *************** ***********@mic rosoft.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*******@comm unity.nospam> wrote in message
news:95******** *************** ***********@mic rosoft.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(Se rver.MapPath("f ile.txt"), false, Encoding.UTF8)) {
streamWriter.Wr ite("£");
}

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(Se rver.MapPath("f ile.txt"), false, Encoding.UTF8)) {
streamWriter.Wr ite("£");
}

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 :

<globalizatio n
requestEncoding ="iso-8859-1"
responseEncodin g="iso-8859-1"
fileEncoding="i so-8859-1"
/>

<globalizatio n
requestEncoding ="UTF-8"
responseEncodin g="UTF-8"
fileEncoding="U TF-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*******@comm unity.nospam> wrote in message
news:7A******** *************** ***********@mic rosoft.com...
nope, that gives me... £

not quite sure why im getting the  !?

"Mark Rae" wrote:
"musosdev" <mu*******@comm unity.nospam> wrote in message
news:95******** *************** ***********@mic rosoft.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
"windows125 2", 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(objec t sender, EventArgs e)
{
Encoding enc = Encoding.GetEnc oding("Windows-1252");
string txt = enc.GetString(n ew 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
25948
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
1
2019
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 == 'inline') { icon.src = icon.CollaspedSrc; e.src = e.CollaspedSrc;
2
3818
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
1363
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 PDF opens in a new window - until a filename containing a # sign is clicked. A window still opens up but I get the dreaded 'Page cannot be displayed' error. I wrapped the filename around the encode method so that the # sign is properly encoded,...
8
3454
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 I access the array elements. Thanks for your help. #include <stdio.h>
1
1811
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 IST 2007
14
5555
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
712
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
4766
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 says 'Cannot save the digital signature at this time' and suggests that I 'package and sign' the file from the Microsoft Office Button / Publish / Publish and Sign menu option. I am able to do this but it saves my add-in as a signed package...
0
9699
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
10309
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...
0
10068
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
9119
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
7600
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
6840
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();...
0
5496
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
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
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.