skip to Main Content

Sorry I am still a beginner but slowly getting there. I want to change all the "base-purchase-prices" by a % all at once? I am tearing my hair out trying to work out how to do it. There are 7000 line items so simply saying "get a calculator" is not going to work

{ 
  "tradeable-code": "Scissors_01", 
  "base-purchase-price": "110", 
  "base-sell-price": "12", 
  "delta-price": "-1.0", 
  "can-be-purchased":"default" 
},
{ 
  "tradeable-code": "Scissors_Plastic", 
  "base-purchase-price": "88", 
  "base-sell-price": "9", 
  "delta-price": "-1.0", 
  "can-be-purchased":"default" 
},

2

Answers


  1. You can use the extension Regex Text Generator

    • select all the base-purchase-price prices
      • perform a regex find with: (?<="base-purchase-price": ")([^"]*)
      • press Alt+Enter while focus in Find dialog
    • Execute command: Generate text based on Regular Expression (regex)
    • for Match Original Text Regular Expression enter: (.*)
    • for Generator Regular Expression enter: {{=N[1]*1.05:fixed(2):simplify}}
    • this increases the prices with 5% (1+0.05) and rounds it to 2 decimal digits
    • if you like the preview type Enter otherwise Esc
    • press Esc to leave Multi Cursor Mode
    Login or Signup to reply.
  2. Using this extension: Find and Transform, full disclosure – written by me, it is easy to do math on any values in your file.

    For example, make this keybinding, in your keybindings.json file (it could also be made into a setting that will become a command in the Command Palette if you want:

    {
      "key": "alt+c",                    // whatever keybinding you want
      "command": "findInCurrentFile",
      "args": {
        "find": "(?<=base-purchase-price":\s*")(\d+)",
        "isRegex": true,
        "replace": [
          "$${",
            
            "return ($1 * 1.05).toFixed(2);", 
    
          "}$$"
        ]
      }
    

    The find will capture only the digits you want to change. The replace will run any math (or string) operation you want. Here I simply multiplied the capture group $1 by 1.05 and set it to 2 decimal places.

    capture and change a value by a percentage

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search