Digression - String Interpolation
Since scala 2.10, we can define processed strings
- String starting with s embeds expression using $id or ${ }
- String starting with f formats the results of the expressions
- %02d means format the integer with 2 digits, left padding it with zeroes
scala> val n = 20
n: Int = 20
scala> s"Value = $n"
res6: String = Value = 20
scala> f"Hex Value = $n%02x"
res8: String = Hex Value = 14
Since scala 2.10, we can define processed strings
- String starting with s embeds expression using $id or ${ }
- String starting with f formats the results of the expressions
- %02d means format the integer with 2 digits, left padding it with zeroes
scala> val n = 20
n: Int = 20
scala> s"Value = $n"
res6: String = Value = 20
scala> f"Hex Value = $n%02x"
res8: String = Hex Value = 14
No comments:
Post a Comment