Community
    • Login

    Advanced replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 144 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.
    • Américo J. C. SousaA
      Américo J. C. Sousa
      last edited by

      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

      Mark OlsonM 1 Reply Last reply Reply Quote 1
      • guy038G
        guy038
        last edited by guy038

        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 the Replace 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

        1 Reply Last reply Reply Quote 3
        • Mark OlsonM
          Mark Olson @Américo J. C. Sousa
          last edited by Mark Olson

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

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