6

Just trying to convert an integer to a string.

vars.put("test", i);

I'd like to put the value in the variable "test", but it does not working and I think I must convert the int to a string. But I have no idea how to do that. I just found a out how to parsing string to integer in BeanShellSampler.

Paili
  • 825
  • 5
  • 18
  • 30

3 Answers3

18

Use String.valueOf() method

vars.put("test", String.valueOf(i));

Additional information on Beanshell scripting in JMeter - How to Use BeanShell: JMeter's Favorite Built-in Component

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
3

There is yet a shortcut way, how to cast an int i to String s:

String s = ""+i; .. just that simple!

So the asked example:

vars.put("test", ""+i);

..Seriously, nobody gave that answer yet? See i.e. 4105331 for further info.

Franta
  • 986
  • 10
  • 17
-1

BeanShell is a Java scripting language, so anything that works in Java should work in BeanShell, too.

I tend to use vars.put("test", new Integer(i).toString());

If i is already an Integer, you only need to do vars.put("test", i.toString());

RowlandB
  • 563
  • 5
  • 13