LoginSignup
0
0

More than 5 years have passed since last update.

ちょっとしたことがGroovy 「リストの文字列表現で要素に任意の引用符つけたい」

Last updated at Posted at 2013-06-27

テキストのリストに任意の引用符つけたい。

quateToString()
List.metaClass.toString = { squate,equate=null ->
  if(equate==null) equate = squate
  delegate.collect {"${squate}${it}${equate}"}
}
def l = ["a","b","c"];
println l.toString()
println l.toString("'")

常にこれでいいってわけではないけど。

追記:
シングルクオート以外にもこんなのとか行けます。

class cntP{
  def i=0;
  @Override
  String toString(){
    /<p class="num_${i++}">/
  }
}

println l.toString(new cntP(),"</p>")

出力こんなです。

[<p class="num_0">a</p>, <p class="num_1">b</p>, <p class="num_2">c</p>]
0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0