Skip to content

Instantly share code, notes, and snippets.

@aeg
Created November 12, 2013 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeg/7433549 to your computer and use it in GitHub Desktop.
Save aeg/7433549 to your computer and use it in GitHub Desktop.
複数行の文字列を取り扱う
// Case #1
// 複数行の文字列(改行を含んだ文字列)を定義するには"""を使う。
def name = "文字列"
def str = """こんにちは
${name}さん
複数行に渡る
文字列です。"""
println str
/* 結果
こんにちは
文字列さん
複数行に渡る
文字列です。
*/
// Case #2
// 複数行の文字列を1行ずつ処理する
str = """こんにちは
複数行さん
複数行に渡る
文字列です。"""
str.eachLine { line -> println "**${line}**" }
/* 結果
**こんにちは**
**複数行さん**
**複数行に渡る**
**文字列です。**
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment