The GString concept in Groovy is pretty powerful (see http://groovy.codehaus.org/Strings+and+GString).
GStrings let you do things like:
world = "World"
println "Hello ${world}"
# Output: Hello World
println "1+2 = ${1+2}"
# Output: 1+2 = 3
println "${System.exit(-1)}"
# Program terminated
I'm trying to figure out if using Groovy GStr...
Groovy has a concept of GStrings. I can write code like this:
def greeting = 'Hello World'
println """This is my first program ${greeting}"""
I can access the value of a variable from within the String.
How can I do this in Python?
--
Thanks
...
Hello,
i've got a word document saved in xml format. In this document, there are some GString Tag like $name.
In my groovy code, i load the xml file to replace this GString tag like this:
def file = new File ('myDocInXml.xml')
def name = 'myName'
file.eachLine { line ->
println line
}
But it doesn't works. The G...
Hi, All!
I'm want use $ macro in groovy GString. When i'm wrote this code
['cdata','tdata'].each {
def sql = "select * from $it_1"
}
i'm get error unknown property $it_
ok, i'm rewrite it
['cdata','tdata'].each {
def sql = "select * from ${it}_1"
}
then i'm get unwanted quotes in result string - "select * from 'cdata'_1"
...
This works as expected in a GSP-page:
<td>${Foo.findAllByBar(bar)}</td>
But when adding a collect statement the code breaks ..
<td>${Foo.findAllByBar(bar).collect { it.name }}</td>
with
Error 500: Could not parse script [...gsp]: startup failed,
...: 129: expecting '}', found ')'
@ line 129, column 196. 1 error`.
I wa...
I am hoping to use Groovy more as a functional language than I can with Java, but one area that seems to be a problem is when I call to a stored procedure, as I am passing perhaps 40 parameters in a single call, but, I also need to do some prep work, at the moment before I even call.
So, for example, I need a time stamp, so I will have ...
I have the following code:
public class TestGr
{
static String aaa = "wwww";
public static void main(args)
{
println "["+getAAA()+"]";
println "[" + getBBB() +"]";
}
static String getAAA()
{
return ""
+ "${aaa}"
}
static String getBBB()
{
return "" + "${aaa}"
}
}
The output of this code is:...
I am picking up Groovy. The language is fine. But I have a non-technical problem. One of the classes is called GString. In some context, it can be misleading. And mentioning it is not very appropriate in the office, especially when some non-technical female colleagues are around.
I guess this is not enough to justify renaming the class ...