Remove certain characters from a string/RichTextBox?

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

    Remove certain characters from a string/RichTextBox?

    Hi,

    My VB is very rusty I'm afraid! What would be the most efficient way to
    remove the following ASCII characters from a string?

    à è ì ò ù À È Ì Ò Ù
    á é í ó ú ý Á É Í Ó Ú Ý
    â ê î ô û Â Ê Î Ô Û
    ã ñ õ Ã Ñ Õ
    ä ë ï ö ü ÿ Ä Ë Ï Ö Ü Y o O æ Æ
    ¡ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± º ¹ ² ³ ´ · » ¼ ½ ¾ ¿
    Å å Ç ç Ð Ø ø ð µ × Þ þ ß . -

    I want to load the contents of a file (which contains normal numbers &
    letters aswell as the ones above) and then remove each occurance of each
    unwanted character.

    Preferably I want to show the contents of the file in the RichTextBox and
    then press a command button to remove the ASCII characters and then update
    the RichTextBox.

    I just need some clever person to tell me how I can remove these horrible
    characters! I'm guessing one way is setting up an array with these
    characters in, then looping through the RichTextBox to seek out the
    occurances of each character? If only I knew how to do this!

    Thanks
    Paul



  • GhostInAK

    #2
    Re: Remove certain characters from a string/RichTextBox?

    Hello Paul,

    Take a look at System.String

    -Boo
    Hi,
    >
    My VB is very rusty I'm afraid! What would be the most efficient way
    to remove the following ASCII characters from a string?
    >
    à è ì ò ù À È Ì Ò Ù
    á é í ó ú ý Á É Í Ó Ú Ý
    â ê î ô û Â Ê Î Ô Û
    ã ñ õ Ã Ñ Õ
    ä ë ï ö ü ÿ Ä Ë Ï Ö Ü Y o O æ Æ
    ¡ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± º ¹ ² ³ ´ · » ¼ ½ ¾ ¿
    Å å Ç ç Ð Ø ø ð µ × Þ þ ß . -
    I want to load the contents of a file (which contains normal numbers &
    letters aswell as the ones above) and then remove each occurance of
    each unwanted character.
    >
    Preferably I want to show the contents of the file in the RichTextBox
    and then press a command button to remove the ASCII characters and
    then update the RichTextBox.
    >
    I just need some clever person to tell me how I can remove these
    horrible characters! I'm guessing one way is setting up an array with
    these characters in, then looping through the RichTextBox to seek out
    the occurances of each character? If only I knew how to do this!
    >
    Thanks
    Paul

    Comment

    • Mrozu

      #3
      Re: Remove certain characters from a string/RichTextBox?

      Hi

      Maybe i'm not very clever but what about replace function?:it can't
      be?

      Imports System.Text.Reg ularExpressions
      ..
      ..
      Regex.Replace(v alue, "old char", "new char"))


      what about it??

      Mrozu

      Paul napisal(a):
      Hi,
      >
      My VB is very rusty I'm afraid! What would be the most efficient way to
      remove the following ASCII characters from a string?
      >
      à è ì ò ù À È Ì Ò Ù
      á é í ó ú ý Á É Í Ó Ú Ý
      â ê î ô û Â Ê Î Ô Û
      ã ñ õ Ã Ñ Õ
      ä ë ï ö ü ÿ Ä Ë Ï Ö Ü Y o O æ Æ
      ¡ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± º ¹ ² ³ ´ · » ¼ ½ ¾ ¿
      Å å Ç ç Ð Ø ø ð µ × Þ þ ß . -
      >
      I want to load the contents of a file (which contains normal numbers &
      letters aswell as the ones above) and then remove each occurance of each
      unwanted character.
      >
      Preferably I want to show the contents of the file in the RichTextBox and
      then press a command button to remove the ASCII characters and then update
      the RichTextBox.
      >
      I just need some clever person to tell me how I can remove these horrible
      characters! I'm guessing one way is setting up an array with these
      characters in, then looping through the RichTextBox to seek out the
      occurances of each character? If only I knew how to do this!

      Thanks
      Paul

      Comment

      • Mrozu

        #4
        Re: Remove certain characters from a string/RichTextBox?

        Hi

        Maybe i'm not very clever but what about replace function?:it can't
        be?

        Imports System.Text.Reg ularExpressions
        ..
        ..
        Regex.Replace(v alue, "old char", "new char"))


        what about it??

        Mrozu

        Paul napisal(a):
        Hi,
        >
        My VB is very rusty I'm afraid! What would be the most efficient way to
        remove the following ASCII characters from a string?
        >
        à è ì ò ù À È Ì Ò Ù
        á é í ó ú ý Á É Í Ó Ú Ý
        â ê î ô û Â Ê Î Ô Û
        ã ñ õ Ã Ñ Õ
        ä ë ï ö ü ÿ Ä Ë Ï Ö Ü Y o O æ Æ
        ¡ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± º ¹ ² ³ ´ · » ¼ ½ ¾ ¿
        Å å Ç ç Ð Ø ø ð µ × Þ þ ß . -
        >
        I want to load the contents of a file (which contains normal numbers &
        letters aswell as the ones above) and then remove each occurance of each
        unwanted character.
        >
        Preferably I want to show the contents of the file in the RichTextBox and
        then press a command button to remove the ASCII characters and then update
        the RichTextBox.
        >
        I just need some clever person to tell me how I can remove these horrible
        characters! I'm guessing one way is setting up an array with these
        characters in, then looping through the RichTextBox to seek out the
        occurances of each character? If only I knew how to do this!

        Thanks
        Paul

        Comment

        • Paul

          #5
          Re: Remove certain characters from a string/RichTextBox?

          Yes that works but it looks very bad.

          I was hoping to set up an array and loop through the RichTextBox but thanks
          anyway!

          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "à", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "è", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ì", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ò", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ù", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "À", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "È", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ì", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ò", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "(Ù)", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "á", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "é", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "í", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ó", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ú", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ý", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Á", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "É", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Í", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ó", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ú", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "(Ý)", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "â", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ê", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "î", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ô", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "û", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Â", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ê", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Î", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ô", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Û", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ã", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ñ", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "õ", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ã", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ñ", " ")
          RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Õ", " ")


          Paul


          "Mrozu" <grzesiek.mrozu @gmail.comwrote in message
          news:1157489308 .786190.301640@ i3g2000cwc.goog legroups.com...
          Hi

          Maybe i'm not very clever but what about replace function?:it can't
          be?

          Imports System.Text.Reg ularExpressions
          ..
          ..
          Regex.Replace(v alue, "old char", "new char"))


          what about it??

          Mrozu

          Paul napisal(a):
          Hi,
          >
          My VB is very rusty I'm afraid! What would be the most efficient way to
          remove the following ASCII characters from a string?
          >
          à è ì ò ù À È Ì Ò Ù
          á é í ó ú ý Á É Í Ó Ú Ý
          â ê î ô û Â Ê Î Ô Û
          ã ñ õ Ã Ñ Õ
          ä ë ï ö ü ÿ Ä Ë Ï Ö Ü Y o O æ Æ
          ¡ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± º ¹ ² ³ ´ · » ¼ ½ ¾ ¿
          Å å Ç ç Ð Ø ø ð µ × Þ þ ß . -
          >
          I want to load the contents of a file (which contains normal numbers &
          letters aswell as the ones above) and then remove each occurance of each
          unwanted character.
          >
          Preferably I want to show the contents of the file in the RichTextBox and
          then press a command button to remove the ASCII characters and then update
          the RichTextBox.
          >
          I just need some clever person to tell me how I can remove these horrible
          characters! I'm guessing one way is setting up an array with these
          characters in, then looping through the RichTextBox to seek out the
          occurances of each character? If only I knew how to do this!
          >
          Thanks
          Paul

          Comment

          • hoffman.adam@gmail.com

            #6
            Re: Remove certain characters from a string/RichTextBox?

            If you have the list of the unwanted characters in a file, you could
            read in the file line by line, split the line by spaces, and loop
            through doing a replace that way. Something like this

            Dim fs As New FileStream(Your UnwantedCharFil eLoc, FileMode.Open,
            FileAccess.Read )
            Dim g As New StreamReader(fs )
            dim numchars as integer
            'make sure you start at the beginning
            g.BaseStream.Se ek(0, SeekOrigin.Begi n)
            Dim ArrayLine() As char
            'while you are not at the end of the file
            While g.Peek() -1
            'split into chars
            ArrayLine = Split(g.ReadLin e(), " ")
            For numchars = 0 to ArrayLine.Lengt h
            RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t,
            ArrayLine(numch ars), " ")
            next
            End While

            Comment

            • Douglas Richard

              #7
              Re: Remove certain characters from a string/RichTextBox?


              Paul wrote:
              Yes that works but it looks very bad.
              >
              I was hoping to set up an array and loop through the RichTextBox but thanks
              anyway!
              >
              You can replace multiple characters with a single RegEx.Replace() call.
              Supply a list of all the characters you want to replace, surrounded by
              square "[", "]" brackets.

              the statement:

              Regex.Replace(" abcdefg", "[aceg]", " ")

              returns the string " b d f ".

              Comment

              • Paul

                #8
                Re: Remove certain characters from a string/RichTextBox?

                Thanks but I get a error before I'm able to compile...

                Value of type '1-dimensional array of String' cannot be converted to
                '1-dimensional array of Char' because 'String' is not derived from 'Char'.

                It occurs on this line...
                ArrayLine = Split(g.ReadLin e(), " ")

                Any ideas what that could mean?

                Paul


                <hoffman.adam@g mail.comwrote in message
                news:1157495785 .150450.217370@ d34g2000cwd.goo glegroups.com.. .
                If you have the list of the unwanted characters in a file, you could
                read in the file line by line, split the line by spaces, and loop
                through doing a replace that way. Something like this
                >
                Dim fs As New FileStream(Your UnwantedCharFil eLoc, FileMode.Open,
                FileAccess.Read )
                Dim g As New StreamReader(fs )
                dim numchars as integer
                'make sure you start at the beginning
                g.BaseStream.Se ek(0, SeekOrigin.Begi n)
                Dim ArrayLine() As char
                'while you are not at the end of the file
                While g.Peek() -1
                'split into chars
                ArrayLine = Split(g.ReadLin e(), " ")
                For numchars = 0 to ArrayLine.Lengt h
                RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t,
                ArrayLine(numch ars), " ")
                next
                End While
                >

                Comment

                • Paul

                  #9
                  Re: Remove certain characters from a string/RichTextBox?

                  Thanks Douglas, I've incorporated this into my project, had no idea about
                  the square brackets!"

                  Paul


                  "Douglas Richard" <djrichard@gmai l.comwrote in message
                  news:1157600193 .935705.105480@ d34g2000cwd.goo glegroups.com.. .
                  >
                  Paul wrote:
                  >Yes that works but it looks very bad.
                  >>
                  >I was hoping to set up an array and loop through the RichTextBox but
                  >thanks
                  >anyway!
                  >>
                  >
                  You can replace multiple characters with a single RegEx.Replace() call.
                  Supply a list of all the characters you want to replace, surrounded by
                  square "[", "]" brackets.
                  >
                  the statement:
                  >
                  Regex.Replace(" abcdefg", "[aceg]", " ")
                  >
                  returns the string " b d f ".
                  >

                  Comment

                  Working...