PC Review


Reply
Thread Tools Rate Thread

Pound symbol in a string

 
 
Paul Hadfield
Guest
Posts: n/a
 
      25th Feb 2005
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.


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      25th Feb 2005
Paul,

"Paul Hadfield" <(E-Mail Removed)> 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/>

 
Reply With Quote
 
 
 
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      25th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Paul Hadfield
Guest
Posts: n/a
 
      28th Feb 2005
Thats great - works a treat

Jay - you're a star!!!!

Cheers,
Paul.


"Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> 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.
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing Pound Sterling symbol Robert J. Lafayette Windows XP Basics 4 26th Sep 2006 03:38 PM
When I try to use the pound symbol I get a hash symbol, =?Utf-8?B?Z3JlZW5maW5nZXJz?= Microsoft Word Document Management 2 22nd Dec 2004 12:08 AM
I cant find a pound symbol on my keyboard =?Utf-8?B?SGVucnk=?= Microsoft Access 4 6th Sep 2004 12:34 AM
Server.HTMLEncode and the # (pound) symbol Chris Microsoft ASP .NET 2 15th Jul 2004 02:03 AM
Re: pound symbol is replaced by ? Rob Schneider Windows XP General 6 23rd Sep 2003 07:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:52 AM.