Deleting unnecessary symbols from variable in Jmeter

2k views Asked by At

I have variable as string in this view:

["564546","56454654","3123123","868987"]

I need the script that deletes unnecessary symbols [ ] " and put it to another variable . (something like trim method) I assume it should be made in BeanShell pre-processor.

1

There are 1 answers

0
Dmitri T On BEST ANSWER

It can be done via Beanshell PreProcessor as follows:

  1. Add Beanshell PreProcessor as a child of the request which needs "another variable"
  2. Put the following code into the PreProcessor's "Script" area:

    String yourvar = vars.get("yourvar");
    String anothervar = yourvar.replace("[","").replace("]","").replaceAll("\\\"","");
    vars.put("anothervar",anothervar);
    

Change "yourvar" and "anothervar" according to your variables reference names.

  • yourvar - source variable name
  • anothervar - result variable name

vars is a shorthand to JMeterVariables class instance which provides access to JMeter variables in current context. See JavaDoc for the class for all available methods and How to use BeanShell: JMeter's favorite built-in component guide for advanced information on Beanshell scripting in JMeter.