2

I created a user defined variable i and put value 0. In groovy I try to run on a list starting [i], but it returned 48. when I hard coded put 0, the script is OK why I is set to 48?

List<String> myList = props.get("myListKey");
int i = vars.get("i"); 
String id = myList[i];
//String id = myList[0];
System.out.println("id:  " + id);
vars.putObject("id", id);
System.out.println("I is:  " + i);

enter image description here

enter image description here

enter image description here

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
Bastian
  • 1,089
  • 7
  • 25
  • 74

1 Answers1

3

The correct way to convert String to number in groovy is using toInteger() function:

int value =  vars.get("i").toInteger()    
log.info("I2 is:  " + value);

Currently you return the ASCII value of character 0 (48). you can check also other options to convert String to int.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233