摘要:資料形態
一、String
/*
可以用單引號或是雙引號來宣告字串
*/
var s1 = 'Hello s1';
var s2 = "Hello s2";
println("s1 = {s1}");//output:s1 = Hello s1
println("s2 = {s2}");//output:s2 = Hello s2
/*
宣告字串時可以用大括弧包住一個某字串變數,當作新字串變數的一部分
*/
def name = 'Joe';
var s = "Hello {name}";
println("name = {name}");//output:name = Joe
println("s = {s}");//output:s = Hello Joe
/*
宣告字串時可以用大括弧包住一個判斷敘述,將結果當作新字串變數的一部分
*/
def answer = true;
var s3 = "The answer is {if (answer) "Yes" else "No"}";
println("s3 = {s3}");//output:s = The answer is Yes
/*
使用多個字串變數來宣告一個新的字串變數,還是使用大括弧
*/
def one = "This example ";
def two = "joins two strings.";
def three = "{one}{two}"; // join string one and string two
println("three = {three}");//output:three = This example joins two strings.