在Beanshell脚本中生成序列号(Generating sequence number in Beanshell scripting)

编程入门 行业动态 更新时间:2024-10-24 18:22:16
在Beanshell脚本中生成序列号(Generating sequence number in Beanshell scripting)

我是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

更多推荐

本文发布于:2023-07-27 05:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1285490.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列号   脚本   Beanshell   Generating   scripting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!