[CHANGE] Output examples added to matcher part and string interpolation part.

This commit is contained in:
a.vandijk 2014-08-15 15:47:12 +02:00
parent 07b6229ee6
commit d2cf006282

View File

@ -332,11 +332,10 @@ val matcher = (value: String) => {
}) })
} }
matcher("mrbean@pyahoo.com") matcher("mrbean@pyahoo.com") // => "It was an email: mrbean"
matcher("nope..") matcher("nope..") // => "No match on 'nope..'"
matcher("52917") matcher("52917") // => "No match on '52917'"
matcher("52752-16432-22178-47917") matcher("52752-16432-22178-47917") // => "Serial key: 52752, 16432, 22178, 47917"
// Strings // Strings
@ -359,13 +358,13 @@ println(s"We have $n apples")
// Expressions inside interpolated strings are also possible // Expressions inside interpolated strings are also possible
val a = Array(11, 9, 6) val a = Array(11, 9, 6)
println(s"My second daughter is ${a(0) - a(2)} years old") println(s"My second daughter is ${a(0) - a(2)} years old") // => "My second daughter is 5 years old"
println(s"We have double the amount of ${n / 2.0} in apples.") println(s"We have double the amount of ${n / 2.0} in apples.") // => "We have double the amount of 22.5 in apples."
println(s"Power of 2: ${math.pow(2, 2)}") // Power of 2: 4.0 println(s"Power of 2: ${math.pow(2, 2)}") // => "Power of 2: 4"
// Formatting with interpolated strings (note the prefixed f) // Formatting with interpolated strings (note the prefixed f)
println(f"Power of 5: ${math.pow(5, 2)}%1.0f") // Power of 5: 25 println(f"Power of 5: ${math.pow(5, 2)}%1.0f") // "Power of 5: 25"
println(f"Square root of 122: ${math.sqrt(122)}%1.4f") // Square root of 122 println(f"Square root of 122: ${math.sqrt(122)}%1.4f") // "Square root of 122"
// Ignoring special characters. // Ignoring special characters.
println(raw"New line feed: \n. Carriage return: \r.") println(raw"New line feed: \n. Carriage return: \r.")