我只是想将一个整数转换为字符串。
vars.put("test", i);
我想将值放在变量“test”中,但它没有起作用,我认为我必须将int转换为字符串。但我不知道怎么做。我只是在BeanShellSampler中找到了如何将字符串解析为整数。
使用String.valueOf()方法。
vars.put("test", String.valueOf(i));
JMeter中关于Beanshell脚本的额外信息 - How to Use BeanShell: JMeter's Favorite Built-in Component
int i
转换为 String s
:
所以,针对你提出的例子:
String s = "" + i;
.. 就是这么简单!
.. 真的没有人给出过这个答案吗?更多信息请参见例如 4105331。
vars.put("test", "" + i);
BeanShell是一种Java脚本语言,因此在Java中可用的任何内容也应该可以在BeanShell中使用。
我倾向于使用vars.put("test", new Integer(i).toString());
如果i
已经是一个Integer
,那么你只需要执行vars.put("test", i.toString());