streamreader will not read UK pound sign!!!

Discussion in 'ASP .Net' started by =?Utf-8?B?bTAwbm0wbmtleQ==?=, Nov 21, 2005.

  1. 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?


    --
    welcome to the mooon !
    =?Utf-8?B?bTAwbm0wbmtleQ==?=, Nov 21, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?bTAwbm0wbmtleQ==?=

    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.


    "m00nm0nkey" <> skrev i meddelandet news:...
    > 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?
    >
    >
    > --
    > welcome to the mooon !
    PL, Nov 21, 2005
    #2
    1. Advertising

  3. 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?


    --
    welcome to the mooon !


    "PL" wrote:

    >
    > 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.
    >
    >
    > "m00nm0nkey" <> skrev i meddelandet news:...
    > > 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?
    > >
    > >
    > > --
    > > welcome to the mooon !

    >
    >
    >
    =?Utf-8?B?bTAwbm0wbmtleQ==?=, Nov 21, 2005
    #3
  4. 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 ?



    --
    welcome to the mooon !


    "m00nm0nkey" wrote:

    > 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?
    >
    >
    > --
    > welcome to the mooon !
    >
    >
    > "PL" wrote:
    >
    > >
    > > 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.
    > >
    > >
    > > "m00nm0nkey" <> skrev i meddelandet news:...
    > > > 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?
    > > >
    > > >
    > > > --
    > > > welcome to the mooon !

    > >
    > >
    > >
    =?Utf-8?B?bTAwbm0wbmtleQ==?=, Nov 21, 2005
    #4
  5. 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 "?"



    --
    welcome to the mooon !


    "m00nm0nkey" wrote:

    > 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?
    >
    >
    > --
    > welcome to the mooon !
    >
    >
    > "PL" wrote:
    >
    > >
    > > 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.
    > >
    > >
    > > "m00nm0nkey" <> skrev i meddelandet news:...
    > > > 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?
    > > >
    > > >
    > > > --
    > > > welcome to the mooon !

    > >
    > >
    > >
    =?Utf-8?B?bTAwbm0wbmtleQ==?=, Nov 21, 2005
    #5
  6. =?Utf-8?B?bTAwbm0wbmtleQ==?=

    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.

    "m00nm0nkey" <> skrev i meddelandet news:...
    >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 "?"
    >
    >
    >
    > --
    > welcome to the mooon !
    >
    >
    > "m00nm0nkey" wrote:
    PL, Nov 21, 2005
    #6
  7. =?Utf-8?B?bTAwbm0wbmtleQ==?=

    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.

    "m00nm0nkey" <> skrev i meddelandet news:...
    >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 "?"
    >
    >
    >
    > --
    > welcome to the mooon !
    >
    PL, Nov 22, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry III

    Re: Pound Sign in text emails

    Jerry III, Oct 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    4,435
    Jerry III
    Oct 15, 2003
  2. T.J.
    Replies:
    10
    Views:
    1,389
  3. Simon Harris

    Pound sign - Prefixed with Â

    Simon Harris, Jan 28, 2005, in forum: HTML
    Replies:
    3
    Views:
    12,112
    Simon Harris
    Jan 29, 2005
  4. diablo

    problemm with pound £ sign

    diablo, Dec 19, 2005, in forum: HTML
    Replies:
    5
    Views:
    1,190
    Alan J. Flavell
    Dec 20, 2005
  5. jaems

    pound sign trouble

    jaems, Mar 10, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    713
    Registered User
    Mar 13, 2008
Loading...

Share This Page