groovy数组删除括号 [英] groovy array remove the 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,""])
i (col03,col04,col05,col06,col07,col08,col09,col10,col11,col12,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
i want save col1..col11 into array and call it from select statement, but the problem is that $colarray has the brackets with it (like [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] ), so now i want to remove them, anyone can help with it???thx
推荐答案
def colarray = rolecol.tokenize(',').collect { "col$it" }.join(', ')
然后您还需要转义您的sql:
Then you will also need to escape your sql:
sql.eachRow("select col01, ${Sql.expand(colarray)} from read_csv where col01 = ? and ${Sql.expand('col' + usercol)} != ? ", [file.name,""])
这篇关于groovy数组删除括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!