groovy数组删除括号

时间:2015-01-21 09:56:03

标签: list groovy brackets

  def colarray=[]
                    def num
                    def newRole = rolecol.split(',')
                    def len = newRole.size()
                    println "$newRole,$len"
                    for (num = 0; num < len; num++) {
                        def col = "col"
                        col="$col"+newRole[num]
                        colarray.add(col)

                    }
                    println colarray
                    sql.eachRow("select col01,$colarray from read_csv where col01=? and col${usercol}!=? ", [file.name,""])

我想将col1..col11保存到数组中并从select语句中调用它,但问题是$ colarray有括号(如col03,col04,col05,col06,col07,col08,col09,col10, col11,col12,col13,col14,col15,col16,col17,col18,col19,col20,col21,col22,col23,col24,col25,col26,col27,col28,col29,col30,col31,col32,col33] ),所以现在我想删除它们,任何人都可以帮助它??? thx

2 个答案:

答案 0 :(得分:0)

[]就在那里,因为你在列表上做了一个隐含的toString。使用colarray.join(',')

答案 1 :(得分:0)

def colarray = rolecol.tokenize(',').collect { "col$it" }.join(', ')

然后你还需要转义你的sql:

sql.eachRow("select col01, ${Sql.expand(colarray)} from read_csv where col01 = ? and ${Sql.expand('col' + usercol)} != ? ", [file.name,""])