Loading ...
Sorry, an error occurred while loading the content.

Re: [edit+] I need help to replace

Expand Messages
  • John C Craig
    This looks like a good time to jump in with yet another idea on how to solve this challenge. The code shown here removes all the numbers on each line up to and
    Message 1 of 12 , Aug 27, 2012
    • 0 Attachment
      This looks like a good time to jump in with yet another idea on how to
      solve this challenge. The code shown here removes all the numbers on each
      line up to and including the first space, and leaves the rest of the line
      alone.

      Visual Basic Express is free, and it's extremely powerful. I like it a lot
      and it presents an awesome way to customize Editplus. Of course, I've
      written many books on VB for Microsoft Press and through Books To Believe
      In (great publisher), but VB really does provide an awesome way to
      customize Editplus. I'll show the basic steps here. (You can see my recent
      VB books at VB-Book.com, thank you.)

      Get Visual Basic Express from Microsoft. It's free forever, and it's
      powerful!
      Create a new console application. I named mine epZapNumbers.
      Copy the following code into its module. Note that for 99% of all
      "macros" you'll ever create with this technique, the only code
      you'll need to change is the lines between the two tilde characters
      lines. So this code serves as a great template...

      Module Module1

      Sub Main()

      Dim str As String
      Dim sB As New System.Text.StringBuilder
      Dim ch As Char
      Dim x As Integer

      'Read all of Stdin
      Do
      x = Console.Read()
      If x = -1 Then Exit Do
      ch = Convert.ToChar(x)
      sB.Append(ch)
      Loop

      'Process the contents
      str = Process(sB.ToString)

      'Output the results
      For i As Integer = 0 To str.Length - 1
      Console.Write(str.Substring(i, 1))
      Next

      End Sub

      Private Function Process(ByVal str As String) As String

      'Modify content string here
      Dim sA() As String = Split(str, vbNewLine)

      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      'Removes the number at the start of each line
      For i = 0 To sA.Length - 1
      sA(i) = sA(i).Substring(sA(i).IndexOf(" ") + 1)
      Next

      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      'Return a single string
      Dim ret As String = Join(sA, vbNewLine)
      Return ret

      End Function

      End Module


      Next compile the program to create epZapNumbers.exe in the project's
      folders.
      Find the exe and copy it into your editplus settings folder.

      Now run Editplus and load the file with the 45000+ nicknames. Here's the
      tiny sample
      file I created to test this out...

      1 alfred
      2 john
      3 97Craig
      123 bigger number
      45123 17Sally

      In Editplus...
      View > Toolbars/Views > User Toolbar
      Pulldown the first wrench icon and select Configure User Tools
      A Preferences dialog pops up
      Categories > Tools > User Tools (on the left)
      Pulldown Group1 (or your choice of group)
      Click [Add Tool] button on the right
      Select "Program" in the popup menu
      Enter in the text fields...
      Menu text: "Zap Numbers"
      Command: Browse to selet the epZapNumber.exe file
      Action: Pulldown and select "Run as Text Filter (Replace)"
      [OK]

      That hooks up the console application to one of the wrench tool icons in
      Editplus, and you're now ready to go.

      If you select a few lines and then click on the correct wrench icon tool,
      the line numbers will go away on those lines only.

      If you don't select any lines, the whole file is processed.

      I hope this helps!
      -John


      --
      JohnClarkCraig.com, Sun-Track.com
      LucidLights.com, LucidBrake.com, VB-Book.com
      WritersSummit.com, BooksToBelieveIn.com, Getting-Published.com
      ForTheWealthOfAll.com, Passivillionaire.com


      [Non-text portions of this message have been removed]
    • Doug Fortnam
      dZ I like your latest solution also. There is usually more than one way to solve these. Doug Doug Fortnam dfortnam@aol.com ... From: DZ-Jay To:
      Message 2 of 12 , Aug 27, 2012
      • 0 Attachment
        dZ
        I like your latest solution also. There is usually more than one way to solve these.

        Doug

        Doug Fortnam
        dfortnam@...



        -----Original Message-----
        From: DZ-Jay <dz@...>
        To: editplus <editplus@yahoogroups.com>
        Sent: Mon, Aug 27, 2012 10:44 am
        Subject: Re: [edit+] I need help to replace


        Great! Just keep in mind something: that expression means "match any two
        strings separated by spaces." It doesn't consider whether they are letters or
        numbers or symbols. It may have worked in your particular case, but it is
        always a good idea to be as narrow as possible in matching.

        Also, the parenthesis are used to "group" matches you want to use later. In
        your case, you are only interested in the second part of the match, so you do
        not need the (.*) at the beginning, just the dot-star. The replace string then
        changes to "\1" to represent the first group.

        Cheers!
        dZ.

        On Aug 27, 2012, at 09:51, Live Queens wrote:

        > fixed it
        > worked with
        > find what (.*) +(.*)
        > replace with: \2
        >
        >
        >
        > ________________________________
        > From: DZ-Jay <dz@...>
        > To: editplus@yahoogroups.com
        > Sent: Monday, August 27, 2012 3:19 PM
        > Subject: Re: [edit+] I need help to replace
        >
        >
        >
        > Ok, that's different. So, if I understand correctly, what you have is:
        >
        > 1. A list of username records, one per line
        > 2. Each one prefixed by a number, followed by whitespace
        > 3. The usernames can contain mixed-case letters and numbers
        > 4. You want to remove the numeric prefix and whitespace
        >
        > If the above is correct, then you can try the following:
        >
        > Find: ^[0-9]+ +([a-zA-Z0-9]+)
        > Replace: \1
        >
        > That should work with the example you posted.
        >
        > Notice that the "^" symbol means "match at the beginning of the line." If the
        username records to not start at the beginning of the line, you can remove that.
        However, it will cause it to match *anything* that fits that pattern within the
        line, as many times as it matches.
        >
        > dZ.
        >
        > On Aug 26, 2012, at 20:53, Live Queens wrote:
        >
        >> Doug, i don't have nickname
        >>
        >> nickname are usernames
        >>
        >> like Joana22 Diana32 ..etc
        >>
        >> so the list looks like this
        >>
        >> 1 A00Diana
        >> 2 A0001Ioana16
        >> 3 A1Iuliana
        >> ...
        >> 345256 Z0Andreas23
        >>
        >> And I have to cut off the numbers that are in front of usernames
        >>
        >> and to have an output like this
        >>
        >> A00Diana
        >> A0001Ioana16
        >> A1Iuliana
        >> ...
        >> Z0Andreas23
        >>
        >>
        >>
        >>
        >>
        >>
        >> ________________________________
        >> From: Doug Fortnam <dfortnam@...>
        >> To: editplus@yahoogroups.com
        >> Sent: Monday, August 27, 2012 3:49 AM
        >> Subject: RE: [edit+] I need help to replace
        >>
        >>
        >>
        >> I was playing around with this and could not get dZ's solution to work, but
        >> this worked:
        >>
        >> Find: (.*)[0-9] +(nickname[0-9]+)
        >> Replace: \2
        >>
        >> Doug
        >>
        >> -----Original Message-----
        >> From: editplus@yahoogroups.com [mailto:editplus@yahoogroups.com] On Behalf
        >> Of DZ-Jay
        >> Sent: Sunday, August 26, 2012 8:18 PM
        >> To: editplus@yahoogroups.com
        >> Subject: Re: [edit+] I need help to replace
        >>
        >> Hello:
        >>
        >> You can try something like this (without the quotation marks):
        >>
        >> Find: "[0-9]+(nickname[0-9]+)"
        >> Replace: "\1"
        >>
        >> dZ.
        >>
        >> On Aug 26, 2012, at 17:35, LiveQueens wrote:
        >>
        >>> hello I need to replace
        >>>
        >>> 1 nickname2
        >>> 2 nickname33
        >>> 3 nickname234
        >>> 4 nickname21
        >>> ..(365355 nickname54
        >>>
        >>> output
        >>>
        >>> nickname2
        >>> nickname33
        >>> nickname234
        >>> nickname21
        >>> nickname54
        >>>
        >>> what is the expression i need to use ?
        >>>
        >>> thank you
        >>>
        >>>
        >>
        >> ------------------------------------
        >>
        >> http://www.editplus.comYahoo! Groups Links
        >>
        >>
        >>
        >>
        >> [Non-text portions of this message have been removed]
        >>
        >
        >
        >
        >
        > [Non-text portions of this message have been removed]
        >



        ------------------------------------

        http://www.editplus.comYahoo! Groups Links







        [Non-text portions of this message have been removed]
      • Doug Fortnam
        John, Thanks for sharing this. I have always been an avid VBA user and did not know about VB Express. I am going to try it out. Doug Fortnam dfortnam@aol.com
        Message 3 of 12 , Aug 27, 2012
        • 0 Attachment
          John,
          Thanks for sharing this. I have always been an avid VBA user and did not know about VB Express. I am going to try it out.

          Doug Fortnam
          dfortnam@...



          -----Original Message-----
          From: John C Craig <jccraig@...>
          To: editplus <editplus@yahoogroups.com>
          Sent: Mon, Aug 27, 2012 11:14 am
          Subject: Re: [edit+] I need help to replace


          This looks like a good time to jump in with yet another idea on how to
          solve this challenge. The code shown here removes all the numbers on each
          line up to and including the first space, and leaves the rest of the line
          alone.

          Visual Basic Express is free, and it's extremely powerful. I like it a lot
          and it presents an awesome way to customize Editplus. Of course, I've
          written many books on VB for Microsoft Press and through Books To Believe
          In (great publisher), but VB really does provide an awesome way to
          customize Editplus. I'll show the basic steps here. (You can see my recent
          VB books at VB-Book.com, thank you.)

          Get Visual Basic Express from Microsoft. It's free forever, and it's
          powerful!
          Create a new console application. I named mine epZapNumbers.
          Copy the following code into its module. Note that for 99% of all
          "macros" you'll ever create with this technique, the only code
          you'll need to change is the lines between the two tilde characters
          lines. So this code serves as a great template...

          Module Module1

          Sub Main()

          Dim str As String
          Dim sB As New System.Text.StringBuilder
          Dim ch As Char
          Dim x As Integer

          'Read all of Stdin
          Do
          x = Console.Read()
          If x = -1 Then Exit Do
          ch = Convert.ToChar(x)
          sB.Append(ch)
          Loop

          'Process the contents
          str = Process(sB.ToString)

          'Output the results
          For i As Integer = 0 To str.Length - 1
          Console.Write(str.Substring(i, 1))
          Next

          End Sub

          Private Function Process(ByVal str As String) As String

          'Modify content string here
          Dim sA() As String = Split(str, vbNewLine)

          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          'Removes the number at the start of each line
          For i = 0 To sA.Length - 1
          sA(i) = sA(i).Substring(sA(i).IndexOf(" ") + 1)
          Next

          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          'Return a single string
          Dim ret As String = Join(sA, vbNewLine)
          Return ret

          End Function

          End Module


          Next compile the program to create epZapNumbers.exe in the project's
          folders.
          Find the exe and copy it into your editplus settings folder.

          Now run Editplus and load the file with the 45000+ nicknames. Here's the
          tiny sample
          file I created to test this out...

          1 alfred
          2 john
          3 97Craig
          123 bigger number
          45123 17Sally

          In Editplus...
          View > Toolbars/Views > User Toolbar
          Pulldown the first wrench icon and select Configure User Tools
          A Preferences dialog pops up
          Categories > Tools > User Tools (on the left)
          Pulldown Group1 (or your choice of group)
          Click [Add Tool] button on the right
          Select "Program" in the popup menu
          Enter in the text fields...
          Menu text: "Zap Numbers"
          Command: Browse to selet the epZapNumber.exe file
          Action: Pulldown and select "Run as Text Filter (Replace)"
          [OK]

          That hooks up the console application to one of the wrench tool icons in
          Editplus, and you're now ready to go.

          If you select a few lines and then click on the correct wrench icon tool,
          the line numbers will go away on those lines only.

          If you don't select any lines, the whole file is processed.

          I hope this helps!
          -John


          --
          JohnClarkCraig.com, Sun-Track.com
          LucidLights.com, LucidBrake.com, VB-Book.com
          WritersSummit.com, BooksToBelieveIn.com, Getting-Published.com
          ForTheWealthOfAll.com, Passivillionaire.com


          [Non-text portions of this message have been removed]



          ------------------------------------

          http://www.editplus.comYahoo! Groups Links







          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.