我是Beanshell脚本的新手。 我正在尝试生成序列号,我尝试的脚本代码如下所示
文件名:sequence.bsh
string = new String(); Long[] n = new Long[] {1000}; for (i=0; i < n; i++){ sequence = String.format("%08d", i); System.out.println(sequence); }当我尝试运行此代码时,我得到以下错误:
评估错误:源文件:sequence.bsh:运算符:'“<”'不适合对象:在行:3:在文件中:sequence.bsh :;
上面的代码行在编译的java程序中按预期工作,我从00000001到00009999生成序列。
我需要知道如何纠正这个操作符错误并将结果分配给变量,以便我可以在JMeter测试用例中使用它。 类似于vars.put("VARNAME", i.toString());
提前致谢。
I am new to Beanshell scripting. I am trying to generate sequential numbers, the scripting code I tried is as below
File Name: sequence.bsh
string = new String(); Long[] n = new Long[] {1000}; for (i=0; i < n; i++){ sequence = String.format("%08d", i); System.out.println(sequence); }When I try to run this code I get the below Error:
Evaluation Error: Sourced file: sequence.bsh : Operator: '"<"' inappropriate for objects : at Line: 3 : in file: sequence.bsh : ;
The above lines of code work as expected in a compiled java program & I get sequence generated from 00000001 to 00009999.
I need to know how to rectify this operator error & assign the result to a variable so that I can use it inside a JMeter test case. something like vars.put("VARNAME", i.toString());
Thanks in advance.
最满意答案
Beanshell不是很Java,我猜你需要使用DecimalFormat类而不是String.format()方法。
import java.text.DecimalFormat; DecimalFormat df = new DecimalFormat( "00000000" ); int n = 1000; for (int i=0;i<n;i++) { String sequence = df.format(i); System.out.println(sequence); }有一个很好的Beanshell脚本指南可以帮助很多
Beanshell is not very Java, I guess you need to use DecimalFormat class instead of String.format() method.
import java.text.DecimalFormat; DecimalFormat df = new DecimalFormat( "00000000" ); int n = 1000; for (int i=0;i<n;i++) { String sequence = df.format(i); System.out.println(sequence); }There is a nice Beanshell scripting guide that can help a lot
更多推荐
发布评论