• Login
Community
  • Login

Adding at the number on the beginning of every line

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 414 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    raizkie19
    last edited by Apr 27, 2020, 6:47 AM

    Hello!
    I need some help… I would like to add 100 on the beginning of every line with numbers…

    501#
    A bottle of potion made from grinded Red Herbs.

    ^0000CCType:^000000 Restorative
    ^0000CCHeal:^000000 45 ~ 65 HP
    ^0000CCWeight:^000000 7

    502#
    A bottle of potion made from grinded Red and Yellow Herbs.

    ^0000CCType:^000000 Restorative
    ^0000CCHeal:^000000 105 ~ 145 HP
    ^0000CCWeight:^000000 10

    503#
    A bottle of potion made from grinded Yellow Herbs.

    ^0000CCType:^000000 Restorative
    ^0000CCHeal:^000000 175 ~ 235 HP
    ^0000CCWeight:^000000 13

    So it will be like:
    100501#
    100502#
    100503#

    Thanks in advance!

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 Apr 27, 2020, 7:18 AM Apr 27, 2020, 7:03 AM

      Hello @ryan-jay-alfonso and All,

      Easy with regexes !

      • Open the Replace dialog ( Ctrl + F )

      • SEARCH (?-s)^(?=.+#)

      • REPLACE 100

      • Tick the Wrap around option, if necessary

      • Select the Regular expression search mode

      • Click on the Replace All button

      Voila !

      Notes :

      • First, the in-line modifier (?-s) forces the regex engine to see each regex dot symbol as matching a single standard character ( not EOL ones )

      • Then, it looks for each beginning of line ( regex assertion ^ ), but ONLY IF …

      • A # symbol occurs at end of current line, due to the look-ahead structure (?=.+#)

      • In replacement, we simply write the number 100 at beginning of each line

      Best Regards,

      guy038

      R L 2 Replies Last reply Apr 27, 2020, 7:17 AM Reply Quote 0
      • R
        raizkie19 @guy038
        last edited by Apr 27, 2020, 7:17 AM

        @guy038

        Thank you so much! Its working as intended…

        1 Reply Last reply Reply Quote 1
        • L
          lar3ryca @guy038
          last edited by Apr 28, 2020, 10:31 PM

          @guy038
          Boy, those regexes again. I don’t know about most people, but I find them difficult to remember.
          For this task, I would have used a macro:

          Select Macro->Start Recording
          Search for #
          Press the Home key
          Type 100
          Press the End key
          Select Macro->Stop Recording

          Execute the macro however many times you need.

          1 Reply Last reply Reply Quote 1
          • G
            guy038
            last edited by guy038 Apr 29, 2020, 11:12 AM Apr 29, 2020, 11:11 AM

            Hello, @ryan-jay-alfonso and All,

            Ah, OK ! Here is the macro code that does the work :

                <Macro name="Test_#" Ctrl="no" Alt="yes" Shift="no" Key="187">             <!-- Shortcut : ALT + =      -->
                    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />     <!-- Search Initialisation   -->
                    <Action type="3" message="1601" wParam="0" lParam="0" sParam="#$" />   <!-- Search Regex : # at END -->
                    <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />     <!-- Regular Expression mode -->
                    <Action type="3" message="1702" wParam="0" lParam="512" sParam="" />   <!-- Search Downwards        -->
                    <Action type="3" message="1701" wParam="0" lParam="1" sParam="" />     <!-- Hit on Find Next button -->
                    <Action type="0" message="2453" wParam="0" lParam="0" sParam="" />     <!-- Hit on HOME key         -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="1" />    <!-- Writing of the digit 1  -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="0" />    <!-- Writing of the digit 0  -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="0" />    <!-- Writing of the digit 0  -->
                    <Action type="0" message="2451" wParam="0" lParam="0" sParam="" />     <!-- Hit on END key          -->
                </Macro>
            

            Remark :

            If you’re totally sure that the # only occurs, once, at the end of some specific lines, we can, simply, use the Normal search mode, giving the following macro code :

                <Macro name="Test_#" Ctrl="no" Alt="yes" Shift="no" Key="187">             <!-- Shortcut : ALT + =      -->
                    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />     <!-- Search Initialisation   -->
                    <Action type="3" message="1601" wParam="0" lParam="0" sParam="#" />    <!-- Search of the # symbol  -->
                    <Action type="3" message="1625" wParam="0" lParam="0" sParam="" />     <!-- Normal search mode      -->
                    <Action type="3" message="1702" wParam="0" lParam="512" sParam="" />   <!-- Search Downwards        -->
                    <Action type="3" message="1701" wParam="0" lParam="1" sParam="" />     <!-- Hit on Find Next button -->
                    <Action type="0" message="2453" wParam="0" lParam="0" sParam="" />     <!-- Hit on HOME key         -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="1" />    <!-- Writing of the digit 1  -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="0" />    <!-- Writing of the digit 0  -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="0" />    <!-- Writing of the digit 0  -->
                    <Action type="0" message="2451" wParam="0" lParam="0" sParam="" />     <!-- Hit on END key          -->
                </Macro>
            

            Now,

            • First, determine the location of your active shortcuts.xml configuration file. It depends if you have a local N++ install or not :

              • Along with the notepad++.exe file, for a local configuration, in any folder different from C:\Program files[(x86)]

              • In the path %AppData%\Notepad++, in case of use of the installer to install N++

            • Stop any Notepad++ instance

            • Insert 1 of the codes, above, in the <Macros>........</Macros> node of your active shortcuts.xml file and save it

            • Restart Notepad++

            • Select your file tab

            • Insert a dummy xxx# line, without line-break, at the very end of the file ( This line must satisfy the search ! )

            • Go to the very beginning of file ( Ctrl + Home )

            • Click on the Macros > Run a Macro Multiple Times... menu option

            • Select the Test_# macro, in the drop-down list

            • Choose the Run until the end of file option

            • Click on the Run button

            Reminder : You must move to the very beginning of your file, before running the Run until the end of file option

            Best Regards,

            guy038

            1 Reply Last reply Reply Quote 1
            1 out of 5
            • First post
              1/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors