Reputation: 18923
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
Upvotes: 1
Views: 1371
Reputation: 1539
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
Upvotes: 4