streamreader will not read UK pound sign!!!

G

Guest

This is totally rediculous; please let me know what I am doing wrong here, I
must be doing something really stupid.

This snippit of code is reading a text file, a line at a time:

Dim srPS As New
StreamReader("\\marsweb\TempDataflowHolding\FromDataflow\SQL\Migration\20051121010118_20051121124555_RateUploadSQL_All.SQL")
Dim strFileLine As String

While srPS.Peek <> -1

strFileLine = srPS.ReadLine()

System.Diagnostics.Debug.WriteLine(strFileLine)

End While

srPS.Close()


The last line of the file reads:
"SQLSTRING1|UPDATE SchedulerEventParameter SET epValue = '£' WHERE epSeIndex
= 6 AND epKey= 'strCurrency'"

However, VB.Net reads the line as :
"SQLSTRING1|UPDATE SchedulerEventParameter SET epValue = '' WHERE epSeIndex
= 6 AND epKey= 'strCurrency'"

The pound sign dissapears!! How can this happen?

I tried adding numerous other pound signs within the file and it strips
these out too...I must be doing something silly - what is it I'm doing wrong
here?
 
P

PL

The default encoding for StreamReader is Unicode UTF-8, what encoding is this
textfile in ?

If you want to use UTF-8, make sure the textfile is saved as UTF-8, if you use something
else then specify the encoding when you create the streamreader.

PL.
 
G

Guest

I'm not sure what you mean by Unicode UTF-8, what I can tell you is that the
file is created via another VB.Net program, using a stream writer. No
encoding options are set by the streamwriter object, or streamreader object,
so I assume that it uses a default encoding option.

Should I always specify a default encoding option when I read / Write files?
 
G

Guest

This Unicode option seems to work:
Dim srPS As New
StreamReader("\\marsweb\TempDataflowHoldig\FromDataflow\SQL\Migration\RateUploadSQL_All.TXT", System.Text.UTF8Encoding.UTF7)

UTF8 made no difference
ASCII changed the £ into a ?
 
G

Guest

I have tried reading the file using various encoding methods and found that

System.Text.UTF8Encoding.UTF7 seems to be the only encoding method that will
return the £ character.

I found that UTF8 returned a blank, and ASCII returned a "?"
 
P

PL

Ok, if I was you I would make sure I use the same encoding all over, look into that other
program and change to the same encoding when writing the file so you don't get any nasty
surprises down the road.

Also make sure any initial source is in the encoding you think it is.

PL.
 
P

PL

A final note about this, since you seem to produce queries, if you use MS SQL Server
make sure you use NVARCHAR and NCHAR fields and prefix your literals with N.

For example:

UPDATE SchedulerEventParameter
SET epValue = N'£'
WHERE epSeIndex = 6
AND epKey = N'strCurrency'"

Otherwise SQL Server will treat it with the default encoding (the server settings).

If you end up not using UTF-8 then don't worry about it.

PL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,560
Members
45,035
Latest member
HoTaKeDai

Latest Threads

Top