官术网_书友最值得收藏!

String interpolation

What if we would like to actually print those results? 

First, as you may have already noticed, in one of the examples above, Kotlin provides a nifty println() standard function that wraps the bulkier System.out.println() from Java.

But, more importantly, as in many other modern languages, Kotlin supports string interpolation using the ${} syntax. Following on from the example before:

println("I would suggest: ${suggestGift(10)} ")

The preceding code would print: 

I would suggest: a book

If you're interpolating a variable, and not a function, curly braces could be omitted: 

val gift = suggestGift(100)
println("I would suggest: $gift ")

This would print the following output:

I would suggest: a guitar
主站蜘蛛池模板: 万源市| 河源市| 新建县| 桦南县| 临清市| 龙江县| 西吉县| 射洪县| 行唐县| 车险| 革吉县| 株洲县| 龙胜| 上林县| 阜新市| 成都市| 广德县| 广水市| 闻喜县| 咸阳市| 乌鲁木齐县| 阿图什市| 富裕县| 会宁县| 景德镇市| 崇信县| 舟曲县| 吴堡县| 贵南县| 乐清市| 靖宇县| 麦盖提县| 鹤壁市| 深泽县| 寿宁县| 河池市| 抚远县| 丹寨县| 剑阁县| 泊头市| 福泉市|