LoginSignup
2
0

More than 5 years have passed since last update.

Scalaの文字列補間

Last updated at Posted at 2015-07-28

他の言語だと式展開とか変数展開とかいうやつ。
要は文字列中に変数の値を埋め込むやり方。

val age = 20
println(s"I am $age years old.")
println(f"I am $age%3d years old.")

実行結果

I am 20 years old.
I am  20 years old.

上がs補間子で、文字列中に変数の値を埋め込む、下がf補間子で他の言語の文字列フォーマットみたいなことができる。
他にも補間子あるようですが、とりあえず使いそうなのはこの2つだったのでメモ・・・

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0