streamreader will not read UK pound sign!!!

Discussion in 'ASP .Net' started by Guest, Nov 21, 2005.

  1. Guest

    Guest 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
    Dim strFileLine As String

    While srPS.Peek <> -1

    strFileLine = srPS.ReadLine()


    End While


    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
    Guest, Nov 21, 2005
    1. Advertisements

  2. Guest

    PL Guest

    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, Nov 21, 2005
    1. Advertisements

  3. Guest

    Guest 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?
    Guest, Nov 21, 2005
  4. Guest

    Guest 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 ?
    Guest, Nov 21, 2005
  5. Guest

    Guest 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 "?"
    Guest, Nov 21, 2005
  6. Guest

    PL Guest

    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, Nov 21, 2005
  7. Guest

    PL Guest

    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, Nov 22, 2005
  8. Guest

    Danilo P. Condes Jr.

    Apr 13, 2016
    Likes Received:
    Just use the same Encoding you used or used in creating the file.
    Danilo P. Condes Jr., Apr 13, 2016
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.