1

Is there a method to convert a var to Int in Scala?

Suppose I have:

var noOfConcurrentUsers =  sys.env.get("NumberOfConcurrentUsers");

// I need the following
var userNo = noOfConcurrentUsers //some method

I am getting the variable as an environment variable in String format from Jenkins.

Getting error:

 Cannot resolve symbol toInt
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108

1 Answers1

3

Not sure if I understand correct, but if this conversion from Str to Int then:

var noOfConcurrentUsers = "10";

val i : Int = noOfConcurrentUsers.toInt

EDIT

What worked for me was:

var noOfConcurrentUsers =  sys.env.get("NumberOfConcurrentUsers"); 
var noOfUsers = noOfConcurrentUsers.toString().toInt

Let it be a final nail:)

http://www.scala-lang.org/api/2.9.3/scala/util/Try.html

Pavel
  • 1,519
  • 21
  • 29