Created
November 12, 2013 16:11
-
-
Save aeg/7433549 to your computer and use it in GitHub Desktop.
複数行の文字列を取り扱う
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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