java - Beanshell Scripting in Jmeter -
i trying increment alphanumeric string , pass request in jmeter 2.11. attaching snippet below. please help.
import java.util.*; import java.io.*; var str="baseds66"; var a=1; int position=8; string newstr=str.substring(6,position); //string newstr=str.replace("baseds",""); var n = ${newstr}; //string add = newstr + integer.parseint(1); //string newstr1=sum(newstr + a); //for (int i=0; i<newstr ) vars.put("str",n);
thanks in advance
if need :
- extract
66
- increment
67
- replace original value
baseds66
becomesbaseds67
and store value
${str}
jmeter variable can follows:import java.util.regex.matcher; import java.util.regex.pattern; string str = "baseds66"; pattern p = pattern.compile("(\\d+)", pattern.case_insensitive | pattern.dotall); matcher m = p.matcher(str); if (m.find()) { string originalvaluestring = m.group(1); int originalvalue = integer.parseint(originalvaluestring); originalvalue++; string newstr = str.replace(originalvaluestring, string.valueof(originalvalue)); log.info("incremented value: " + newstr); vars.put("str", newstr); }
demo:
references:
Comments
Post a Comment