473,385 Members | 1,907 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,385 software developers and data experts.

Pound symbol in a string

All,

When I use system.IO.StreamWriter to write append a string to file that
contains the GBP pound symbol, I notice that it also appends an extra
character before the pond symbol. Yet when I examine the string character by
character in the command window, the extra character is not there.

For example:

Dim Line As New StringBuilder
Line.Append("Cost=£10")

Dim SW As StreamWriter
SW = File.AppendText("C:\Test.txt")

SW.WriteLine(Line(0))

SW.Close()

If I then view the contents of the file in notepad it shows:
Cost=£10

If I use a hex editor to view the contents of the file it shows:
43 6F 73 74 3D C2 A3 31 30 0D 0A

Obviously the 0D and 0A at the end are the Cr+Lf charactors, but I don't
understand where the C2 charactor has come from??
Sorry if this is a silly question - I'm really only used to VB6 - still
trying to get my head around dot net.

Cheers,

Paul.
Nov 21 '05 #1
3 6360
Paul,

"Paul Hadfield" <pa**@anon.com> schrieb:
When I use system.IO.StreamWriter to write append a string to file that
contains the GBP pound symbol, I notice that it also appends an extra
character before the pond symbol. Yet when I examine the string character
by character in the command window, the extra character is not there.

For example:

Dim Line As New StringBuilder
Line.Append("Cost=£10")

Dim SW As StreamWriter
SW = File.AppendText("C:\Test.txt")

SW.WriteLine(Line(0))
SW.Close()

If I then view the contents of the file in notepad it shows:
Cost=£10

If I use a hex editor to view the contents of the file it shows:
43 6F 73 74 3D C2 A3 31 30 0D 0A

Obviously the 0D and 0A at the end are the Cr+Lf charactors, but I don't
understand where the C2 charactor has come from??


'StreamWriter' uses UTF-8 as the default encoding. You can change the
encoding used to encode the text written to the file by specifying one of
the 'System.Text.Encoding.*' encodings.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Paul,
As Herfried suggests StreamWriter by default uses UTF8. Normally you want to
use the encoding as specific under your regional settings in Control Panel,
which is Encoding.Default.

Something like:

Imports System.Text

Dim writer As New StreamWriter("Test.txt", True, Encoding.Default)

writer.WriteLine("Cost=£10")

writer.Close()

Hope this helps
Jay

"Paul Hadfield" <pa**@anon.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
All,

When I use system.IO.StreamWriter to write append a string to file that
contains the GBP pound symbol, I notice that it also appends an extra
character before the pond symbol. Yet when I examine the string character
by character in the command window, the extra character is not there.

For example:

Dim Line As New StringBuilder
Line.Append("Cost=£10")

Dim SW As StreamWriter
SW = File.AppendText("C:\Test.txt")

SW.WriteLine(Line(0))

SW.Close()

If I then view the contents of the file in notepad it shows:
Cost=£10

If I use a hex editor to view the contents of the file it shows:
43 6F 73 74 3D C2 A3 31 30 0D 0A

Obviously the 0D and 0A at the end are the Cr+Lf charactors, but I don't
understand where the C2 charactor has come from??
Sorry if this is a silly question - I'm really only used to VB6 - still
trying to get my head around dot net.

Cheers,

Paul.

Nov 21 '05 #3
Thats great - works a treat

Jay - you're a star!!!!

Cheers,
Paul.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:em**************@TK2MSFTNGP14.phx.gbl...
Paul,
As Herfried suggests StreamWriter by default uses UTF8. Normally you want
to use the encoding as specific under your regional settings in Control
Panel, which is Encoding.Default.

Something like:

Imports System.Text

Dim writer As New StreamWriter("Test.txt", True, Encoding.Default)

writer.WriteLine("Cost=£10")

writer.Close()

Hope this helps
Jay

"Paul Hadfield" <pa**@anon.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
All,

When I use system.IO.StreamWriter to write append a string to file that
contains the GBP pound symbol, I notice that it also appends an extra
character before the pond symbol. Yet when I examine the string character
by character in the command window, the extra character is not there.

For example:

Dim Line As New StringBuilder
Line.Append("Cost=£10")

Dim SW As StreamWriter
SW = File.AppendText("C:\Test.txt")

SW.WriteLine(Line(0))

SW.Close()

If I then view the contents of the file in notepad it shows:
Cost=£10

If I use a hex editor to view the contents of the file it shows:
43 6F 73 74 3D C2 A3 31 30 0D 0A

Obviously the 0D and 0A at the end are the Cr+Lf charactors, but I don't
understand where the C2 charactor has come from??
Sorry if this is a silly question - I'm really only used to VB6 - still
trying to get my head around dot net.

Cheers,

Paul.


Nov 21 '05 #4

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...
14
by: Vic Russell | last post by:
Hi, I'm trying to get the British pound (£) symbol through LibXML and just get "£" instead. Any ideas? Vic
5
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...
2
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...
3
by: quat | last post by:
Hi, I have a char* string where I assigned a string literal with the British pound symbol, which is included in the extended ASCII, at least on my OS. However, when I cout the string, I get a...
5
by: Jim Carlock | last post by:
(1) test.php?test_key=test_value $_SERVER returns /test/test.php $_SERVER returns /test/test.php?test_key=test+value $_SERVER returns test_key=test+value (2)...
5
by: ramaswamynanda | last post by:
Hello, I have a currency field on my form. The default formats for this field are dollar, euro. There is no pound symbol.....How do i put in a currency format, having the pound sign. Any help...
1
by: Darren Mansell | last post by:
Hi. I'm relatively new to python so please be gentle :) I'm trying to write a £ symbol to an MS SQL server using pymsssql . This works but when selecting the data back (e.g. using SQL...
0
by: RobR2009 | last post by:
I am having trouble with a C# proxy page I am writing which allows me to do cross domain AJAX calls with Javascript. The problem is with certain pages that contain pound signs £ that are not HTML...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.