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
      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 2 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.