Accent problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Devlon

    #1

    Accent problem

    Hi,

    Can anyone please help me?

    I've wrote a small application that reads the content from a text-file.
    Some characters are not displayed correcly.

    I noticed the text-file uses different types of Accent Signs (').

    Is there some simple methode to replace all of them to just one kind ?

    thanx

    Kind regards

    John


  • Armin Zingler

    #2
    Re: Accent problem

    "John Devlon" <johndevlon@hot mail.comschrieb
    Hi,
    >
    Can anyone please help me?
    >
    I've wrote a small application that reads the content from a
    text-file. Some characters are not displayed correcly.
    >
    I noticed the text-file uses different types of Accent Signs (').
    >
    Is there some simple methode to replace all of them to just one kind
    ?
    >
    thanx

    You must use the correct encoding when reading from the file. When creating
    a StreamReader pass the correct System.Text.Enc oding instance to it's
    constructor.


    Armin

    Comment

    • John Devlon

      #3
      Re: Accent problem


      Hi,

      I added the code below i'm using. I'm using an array instead of an
      arraylist. It's not something i'm proud off, but it works...
      Where do I have to add the encoding ?

      John



      Private arrContentFile( ) As String
      Dim oFile As System.IO.File
      Dim oRead As System.IO.Strea mReader

      Private Sub ReadfileTest(By Val strFilename As String)
      Dim intCount As Int64 = 0
      Dim strLine As String

      Dim objStreamReader = New System.IO.Strea mReader(strFile name)

      strLine = objStreamReader .ReadLine

      Do While Not strLine Is Nothing
      If Not (IsNothing(arrC ontentFile)) Then
      intCount = arrContentFile. GetUpperBound(0 ) + 1
      End If
      ReDim Preserve arrContentFile( intCount)
      arrContentFile( intCount) = strLine

      strLine = objStreamReader .ReadLine
      Loop

      objStreamReader .Close()

      End Sub






      "Armin Zingler" <az.nospam@free net.dewrote in message
      news:%23T$IgTm3 HHA.1204@TK2MSF TNGP03.phx.gbl. ..
      "John Devlon" <johndevlon@hot mail.comschrieb
      >Hi,
      >>
      >Can anyone please help me?
      >>
      >I've wrote a small application that reads the content from a
      >text-file. Some characters are not displayed correcly.
      >>
      >I noticed the text-file uses different types of Accent Signs (').
      >>
      >Is there some simple methode to replace all of them to just one kind
      >?
      >>
      >thanx
      >
      >
      You must use the correct encoding when reading from the file. When
      creating a StreamReader pass the correct System.Text.Enc oding instance to
      it's constructor.
      >
      >
      Armin

      Comment

      • Armin Zingler

        #4
        Re: Accent problem

        "John Devlon" <johndevlon@hot mail.comschrieb
        >
        Hi,
        >
        I added the code below i'm using. I'm using an array instead of an
        arraylist. It's not something i'm proud off, but it works...
        Where do I have to add the encoding ?
        >
        John
        >
        >
        >
        Private arrContentFile( ) As String
        Dim oFile As System.IO.File
        Dim oRead As System.IO.Strea mReader
        >
        Private Sub ReadfileTest(By Val strFilename As String)
        Dim intCount As Int64 = 0
        Dim strLine As String
        >
        Dim objStreamReader = New System.IO.Strea mReader(strFile name)
        >
        strLine = objStreamReader .ReadLine
        >
        Do While Not strLine Is Nothing
        If Not (IsNothing(arrC ontentFile)) Then
        intCount = arrContentFile. GetUpperBound(0 ) +
        1 End If
        ReDim Preserve arrContentFile( intCount)
        arrContentFile( intCount) = strLine
        >
        strLine = objStreamReader .ReadLine
        Loop
        >
        objStreamReader .Close()
        >
        End Sub
        >
        >
        >
        >
        >
        >
        "Armin Zingler" <az.nospam@free net.dewrote in message
        news:%23T$IgTm3 HHA.1204@TK2MSF TNGP03.phx.gbl. ..
        "John Devlon" <johndevlon@hot mail.comschrieb
        Hi,
        >
        Can anyone please help me?
        >
        I've wrote a small application that reads the content from a
        text-file. Some characters are not displayed correcly.
        >
        I noticed the text-file uses different types of Accent Signs
        (').
        >
        Is there some simple methode to replace all of them to just one
        kind ?
        >
        thanx

        You must use the correct encoding when reading from the file. When
        creating a StreamReader pass the correct System.Text.Enc oding
        instance to it's constructor.


        Armin
        First, you should enable Option Strict.

        Then, as written, the Encoding must be passed to the constructor of the
        StreamReader:

        Dim objStreamReader As New System.IO.Strea mReader( _
        strFilename, System.Text.Enc oding.Default _
        )

        I don't know which encoding has been used to write the file, so you first
        have to know this and replace "Default" by the encoding to be used.


        Side notes:
        - You can write "Do Until" instead of "Do While Not"
        - The "Is" Operator is more straightforward than calling the IsNothing
        function.
        - Yes, you could have used an Arraylist. ;-) Or, in FW 2.0, a List(Of
        String).



        Armin

        Comment

        • John Devlon

          #5
          Re: Accent problem

          Dear Mr. Zingler,

          Thanx for your tips... it was very usefull....

          But problem is getting more complex...

          The files I'm trying to read are text-file, created in notepad, using the
          ANSI encoding...
          Resaving a file in notepad to UTF and adjusting the application (encoding
          UTF) works great and solves the problem...

          However, I can't resave every file... How can I correcly read an ANSI
          text-file?

          Kind regards,

          John






          "Armin Zingler" <az.nospam@free net.dewrote in message
          news:uc005Go3HH A.1208@TK2MSFTN GP05.phx.gbl...
          "John Devlon" <johndevlon@hot mail.comschrieb
          >>
          >Hi,
          >>
          >I added the code below i'm using. I'm using an array instead of an
          >arraylist. It's not something i'm proud off, but it works...
          >Where do I have to add the encoding ?
          >>
          >John
          >>
          >>
          >>
          >Private arrContentFile( ) As String
          >Dim oFile As System.IO.File
          >Dim oRead As System.IO.Strea mReader
          >>
          >Private Sub ReadfileTest(By Val strFilename As String)
          > Dim intCount As Int64 = 0
          > Dim strLine As String
          >>
          > Dim objStreamReader = New System.IO.Strea mReader(strFile name)
          >>
          > strLine = objStreamReader .ReadLine
          >>
          > Do While Not strLine Is Nothing
          > If Not (IsNothing(arrC ontentFile)) Then
          > intCount = arrContentFile. GetUpperBound(0 ) +
          >1 End If
          > ReDim Preserve arrContentFile( intCount)
          > arrContentFile( intCount) = strLine
          >>
          > strLine = objStreamReader .ReadLine
          > Loop
          >>
          > objStreamReader .Close()
          >>
          >End Sub
          >>
          >>
          >>
          >>
          >>
          >>
          >"Armin Zingler" <az.nospam@free net.dewrote in message
          >news:%23T$IgTm 3HHA.1204@TK2MS FTNGP03.phx.gbl ...
          "John Devlon" <johndevlon@hot mail.comschrieb
          Hi,
          >
          Can anyone please help me?
          >
          I've wrote a small application that reads the content from a
          text-file. Some characters are not displayed correcly.
          >
          I noticed the text-file uses different types of Accent Signs
          (').
          >
          Is there some simple methode to replace all of them to just one
          kind ?
          >
          thanx
          >
          >
          You must use the correct encoding when reading from the file. When
          creating a StreamReader pass the correct System.Text.Enc oding
          instance to it's constructor.
          >
          >
          Armin
          >
          First, you should enable Option Strict.
          >
          Then, as written, the Encoding must be passed to the constructor of the
          StreamReader:
          >
          Dim objStreamReader As New System.IO.Strea mReader( _
          strFilename, System.Text.Enc oding.Default _
          )
          >
          I don't know which encoding has been used to write the file, so you first
          have to know this and replace "Default" by the encoding to be used.
          >
          >
          Side notes:
          - You can write "Do Until" instead of "Do While Not"
          - The "Is" Operator is more straightforward than calling the IsNothing
          function.
          - Yes, you could have used an Arraylist. ;-) Or, in FW 2.0, a List(Of
          String).
          >
          >
          >
          Armin
          >

          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Accent problem

            "Armin Zingler" <az.nospam@free net.deschrieb:
            Dim objStreamReader As New System.IO.Strea mReader( _
            strFilename, System.Text.Enc oding.Default _
            )
            >
            I don't know which encoding has been used to write the file, so you first
            have to know this and replace "Default" by the encoding to be used.
            Just for the information of the OP: 'Default' refers to the default Windows
            ANSI codepage of the system, which is used by default in the Windows editor
            on Windows XP, for example. If you do not specify any encoding in the
            'StreamReader'' s constructor, UTF-8 is assumed and used.

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

            Comment

            • Armin Zingler

              #7
              Re: Accent problem

              "John Devlon" <johndevlon@hot mail.comschrieb
              Dear Mr. Zingler,
              >
              Thanx for your tips... it was very usefull....
              >
              But problem is getting more complex...
              >
              The files I'm trying to read are text-file, created in notepad,
              using the ANSI encoding...
              Resaving a file in notepad to UTF and adjusting the application
              (encoding UTF) works great and solves the problem...
              >
              However, I can't resave every file... How can I correcly read an
              ANSI text-file?
              See Herfried's answer (System.Text.En coding.Default) .


              Armin

              Comment

              • John Devlon

                #8
                Re: Accent problem

                Dear Mr. Zingler,

                Your provided solutions works great... Like a charm...

                Thank you very much

                John


                "Armin Zingler" <az.nospam@free net.dewrote in message
                news:OGwwdQr3HH A.5160@TK2MSFTN GP05.phx.gbl...
                "John Devlon" <johndevlon@hot mail.comschrieb
                >Dear Mr. Zingler,
                >>
                >Thanx for your tips... it was very usefull....
                >>
                >But problem is getting more complex...
                >>
                >The files I'm trying to read are text-file, created in notepad,
                >using the ANSI encoding...
                >Resaving a file in notepad to UTF and adjusting the application
                >(encoding UTF) works great and solves the problem...
                >>
                >However, I can't resave every file... How can I correcly read an
                >ANSI text-file?
                >
                See Herfried's answer (System.Text.En coding.Default) .
                >
                >
                Armin

                Comment

                Working...