Skip to content

Instantly share code, notes, and snippets.

@sofoklis
Created January 23, 2013 18:13
Show Gist options
  • Save sofoklis/4611174 to your computer and use it in GitHub Desktop.
Save sofoklis/4611174 to your computer and use it in GitHub Desktop.
string interpolation
val st = "String Interpolation" //> st : String = String Interpolation
// s
val s1 = "Lets try $st" //> s1 : String = Lets try $st
val s2 = s"Lets try $st" //> s2 : String = Lets try String Interpolation
val s3 = s"Also arbitrary expressions ${List(1,2,3,4,6) sum}" //> s3 : String = Also arbitrary expressions 16
// f
val height = 1.9d //> height : Double = 1.9
val name = "James" //> name : String = James
val f1 = f"$name%s is $height%2.2f meters tall" //> f1 : String = James is 1.90 meters tall
// raw
val r1 = "avoid\tescaping characters" //> r1 : String = avoid escaping characters
val r2 = """avoid\tescaping characters""" //> r2 : String = avoid\tescaping characters
val r3 = raw"avoid\tescaping characters" //> r3 : String = avoid\tescaping characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment