Reputation: 5867
I am looking at GString $ keyword and want to print the range.
('A'..'Z').each {item ->
print '$item'
}
I was expecting the range A..Z to be printed, but its printing $item$item.... What am I missing here?
Upvotes: 1
Views: 567
Reputation: 2789
Single quoted strings are java.lang.String
and interpolation doesn't work here. You need to change it to GString
, use double quotes:
('A'..'Z').each {item ->
print "$item"
}
It's explained pretty well in Groovy's documentation about strings.
Upvotes: 3