How i could replace a string by incremental value using a block in groovy? -


i'm trying learn how use groovy know ruby

and use code replace string incremental value

 o=0 puts "n,n,n,n,n,n,n,n".gsub(/n/) { o+=1; "#{o}"  }  

for obtain 1,2,3,4,5,6,7,8

how in groovy?

you can same:

def o=0 println 'n,n,n,n,n,n,n,n'.replaceall(/n/) { ++o } 

if want 8 consecutive comma-separated numbers can do

println((1..8).join(',')) 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -