Adding at the number on the beginning of every line
-
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 7502#
A bottle of potion made from grinded Red and Yellow Herbs.^0000CCType:^000000 Restorative
^0000CCHeal:^000000 105 ~ 145 HP
^0000CCWeight:^000000 10503#
A bottle of potion made from grinded Yellow Herbs.^0000CCType:^000000 Restorative
^0000CCHeal:^000000 175 ~ 235 HP
^0000CCWeight:^000000 13So it will be like:
100501#
100502#
100503#Thanks in advance!
-
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
-
-
Thank you so much! Its working as intended…
-
@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 RecordingExecute the macro however many times you need.
-
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 theNormal
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 fromC:\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 activeshortcuts.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
optionBest Regards,
guy038
-