So here is my code:
val regexMeter = """^\s*(\d+,*\d+)\s*[m]\s*$""".r val regexCentimeter = """^\s*(\d+,*\d+)\s*cm\s*$""".r val regexDecimeter = """^\s*(\d+,*\d+)\s*dm\s*$""".r val regexMillimeter = """^\s*(\d+,*\d+)\s*mm\s*$""".r val height = scala.io.StdIn.readLine("Please insert the height of your shape:") height match { case regexMeter(value) => val newValue = value.toDouble*100 case regexCentimeter(value) => val newValue = value.toDouble case regexDecimeter(value) => val newValue = value.toDouble*10 case regexMillimeter(value) => val newValue = value.toDouble/10 case _ => throw new IllegalArgumentException }
So, this is my input, for example: β21 mβ and its selection is only 21, and if its regular expression matches the meters, assigning it val newValue and doing some things with it. But when I now want to print this value of newValue , does it say that it cannot find the value? How can I return this val outside this match case?
source share