Advanced replace
-
Hello
I need help finding and replacing values in a given situation
I have a .xml file and I need to find all the numbers inside this " <ClosingStockQuantity>0.5</ClosingStockQuantity> " and add + 0 to keep all values that have one decimal place with two decimal places.
Thank you
-
Hello, @américo-j-c-sousa, and All,
Easy with regular expressions !
-
Open your file in N++
-
Open the Replace dialog (
Ctrl + H
) -
Untick all box options
-
FIND
<(ClosingStockQuantity)>(\d+\.\d)</ClosingStockQuantity>
-
REPLACE
<$1>${2}0</$1>
-
Check the
Wrap around
option -
Select the
Regular expression
search mode -
Click, once only, on the
Replace All
button or several times on theReplace
button
Voila !
Thus, for this kind of INPUT text :
<ClosingStockQuantity>0.5</ClosingStockQuantity> <ClosingStockQuantity>0.33</ClosingStockQuantity> <ClosingStockQuantity>0.1</ClosingStockQuantity> <ClosingStockQuantity>1</ClosingStockQuantity> <ClosingStockQuantity>4.7</ClosingStockQuantity> <ClosingStockQuantity>97.2</ClosingStockQuantity> <ClosingStockQuantity>123</ClosingStockQuantity>
You should get your expected OUTPUT, below :
<ClosingStockQuantity>0.50</ClosingStockQuantity> <ClosingStockQuantity>0.33</ClosingStockQuantity> <ClosingStockQuantity>0.10</ClosingStockQuantity> <ClosingStockQuantity>1</ClosingStockQuantity> <ClosingStockQuantity>4.70</ClosingStockQuantity> <ClosingStockQuantity>97.20</ClosingStockQuantity> <ClosingStockQuantity>123</ClosingStockQuantity>
Best Regards,
guy038
-
-
@Américo-J-C-Sousa
Try using the find-replace form (Search->Replace
from the main menu or Ctrl+H with default keybindings) and do the following:- Set
Search Mode
to Regular Expressions - Check the Wrap around box
- Find what:
<(ClosingStockQuantity>)(-?\d+)(\.\d)?</ClosingStockQuantity>
- Replace with:
<${1}${2}(?3${3}0:.00)</${1}
This will add a zero as the second decimal place for all numbers that already have one decimal place, and a
.00
after all numbers that don’t yet have any decimal places.Note that this is just manipulating the numbers as text, not doing actual math. If you wanted to do math on the numbers, you will need to use a scripting language.
- Set