Long String concatenation failed

classic Classic list List threaded Threaded
17 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Long String concatenation failed

Jmeter Tea
Hello,
I have to 

concatenate a lot of variables in a script and I want to make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unexpected token: << @ line 2, column 1.
   << vars["id2"] << "<id2>"
Code: String
text ="<id>" <<vars["id1"] << "<id><id2>" << vars["id2"] << "<id2>";

Is there a workaround or a better way concatenation a string in groovy?

Related question:

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Long String concatenation failed

Bay Batu
Hello,

You can use GString that let you put variables into double quotes more easy.

example:

String text = "<id>${vars["id"]}</id>"



2018-09-25 10:56 GMT+03:00 Jmeter Tea <[hidden email]>:
Hello,
I have to 

concatenate a lot of variables in a script and I want to make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unexpected token: << @ line 2, column 1.
   << vars["id2"] << "<id2>"
Code: String
text ="<id>" <<vars["id1"] << "<id><id2>" << vars["id2"] << "<id2>";

Is there a workaround or a better way concatenation a string in groovy?

Related question:

Thank you



--
Reply | Threaded
Open this post in threaded view
|

Re: Long String concatenation failed

Susanne Jaeckel
In reply to this post by Jmeter Tea
Hi!

If I have a hashmap and have to concatenate them the way you show, I
would try:


def vars = ["id": "value", "id2": "value2", "id3": "value3"]

String text = ""
vars.each { k, v ->
         text += "<${k}>${v}</${k}>"
}

println text

Regards,
Susanne.


Am 25.09.2018 um 09:56 schrieb Jmeter Tea:

> Hello,
> I have to concatenate a lot of variables in a script and I want to
> make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
> |
> Caused by:
> org.codehaus.groovy.control.MultipleCompilationErrorsException:
> startup failed:
> Script1.groovy: 2: unexpected token: << @ line 2, column 1.
>    << vars["id2"] << "<id2>"
> Code: Stringtext ="<id>"<<vars["id1"]<<"<id><id2>"<<vars["id2"]<<"<id2>";|
>
> Is there a workaround or a better way concatenation a string in groovy?
>
> Related question:
> https://stackoverflow.com/questions/47786399/jmeter-groovy-script-concatenation-of-variables
>
> Thank you

Reply | Threaded
Open this post in threaded view
|

Re: Long String concatenation failed

Jmeter Tea
Thanks for both answers, but it's not what I need exactly
Regarding Susanne Jaeckel: I want concatenate with specific(not all) values and with different order and prefix for each, e.g. "My Name is"  << vars["first"] >> " " << vars["last"] << "and ..."


Regarding Batuhan Bayrakçı :

I'm using inside JMeter and I'm not supposed to use "${}" it in JMeter script as ${vars["id"]}


On Tue, Sep 25, 2018 at 11:23 AM, Susanne Jaeckel <[hidden email]> wrote:
Hi!

If I have a hashmap and have to concatenate them the way you show, I would try:


def vars = ["id": "value", "id2": "value2", "id3": "value3"]

String text = ""
vars.each { k, v ->
        text += "<${k}>${v}</${k}>"
}

println text

Regards,
Susanne.


Am 25.09.2018 um 09:56 schrieb Jmeter Tea:
Hello,
I have to concatenate a lot of variables in a script and I want to make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
|
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unexpected token: << @ line 2, column 1.
   << vars["id2"] << "<id2>"
Code: Stringtext ="<id>"<<vars["id1"]<<"<id><id2>"<<vars["id2"]<<"<id2>";|

Is there a workaround or a better way concatenation a string in groovy?

Related question:
https://stackoverflow.com/questions/47786399/jmeter-groovy-script-concatenation-of-variables

Thank you


Reply | Threaded
Open this post in threaded view
|

Re: Long String concatenation failed

ericksn
In reply to this post by Jmeter Tea
Looks like a job for MarkupBuilder or StreamingMarkupBuilder

Sent from my iPhone

On Sep 25, 2018, at 3:56 AM, Jmeter Tea <[hidden email]> wrote:

Hello,
I have to 

concatenate a lot of variables in a script and I want to make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unexpected token: << @ line 2, column 1.
   << vars["id2"] << "<id2>"
Code: String
text ="<id>" <<vars["id1"] << "<id><id2>" << vars["id2"] << "<id2>";

Is there a workaround or a better way concatenation a string in groovy?

Related question:

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Long String concatenation failed

Jmeter Tea
Hi Nelson, You mean to use append method as in  StringBuilder:
new StringBuilder().append( foo )
                       .append( bar )
                       .append( www )
                       .toString()

On Tue, Sep 25, 2018 at 2:19 PM, Nelson, Erick <[hidden email]> wrote:
Looks like a job for MarkupBuilder or StreamingMarkupBuilder

Sent from my iPhone

On Sep 25, 2018, at 3:56 AM, Jmeter Tea <[hidden email]> wrote:

Hello,
I have to 

concatenate a lot of variables in a script and I want to make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unexpected token: << @ line 2, column 1.
   << vars["id2"] << "<id2>"
Code: String
text ="<id>" <<vars["id1"] << "<id><id2>" << vars["id2"] << "<id2>";

Is there a workaround or a better way concatenation a string in groovy?

Related question:

Thank you

MG
Reply | Threaded
Open this post in threaded view
|

Re: Long String concatenation failed

MG
In reply to this post by Jmeter Tea
If it is just the CTE that is the problem, you just have ro move the "<<" to the end of the previous line... 

-------- Ursprüngliche Nachricht --------
Von: Jmeter Tea <[hidden email]>
Datum: 25.09.18 09:56 (GMT+01:00)
Betreff: Long String concatenation failed

Hello,
I have to 

concatenate a lot of variables in a script and I want to make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unexpected token: << @ line 2, column 1.
   << vars["id2"] << "<id2>"
Code: String
text ="<id>" <<vars["id1"] << "<id><id2>" << vars["id2"] << "<id2>";

Is there a workaround or a better way concatenation a string in groovy?

Related question:

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Long String concatenation failed

ericksn
In reply to this post by Jmeter Tea

No, I mean markup builder.

Mr Haki says it best….

http://mrhaki.blogspot.com/2009/10/groovy-goodness-creating-xml-with.html

 

 

Erick Nelson

Senior Developer – IT

HD Supply Facilities Maintenance

(858) 740-6523

 

 

From: mg <[hidden email]>
Reply-To: "[hidden email]" <[hidden email]>
Date: Tuesday, September 25, 2018 at 5:19 AM
To: "[hidden email]" <[hidden email]>
Subject: Re: Long String concatenation failed

 

If it is just the CTE that is the problem, you just have ro move the "<<" to the end of the previous line... 

 

-------- Ursprüngliche Nachricht --------

Von: Jmeter Tea <[hidden email]>

Datum: 25.09.18 09:56 (GMT+01:00)

Betreff: Long String concatenation failed

 

Hello,
I have to  concatenate a lot of variables in a script and I want to make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unexpected token: << @ line 2, column 1.
   << vars["id2"] << "<id2>"
 
Code:
String text ="<id>" <<vars["id1"] << "<id><id2>" 
<< vars["id2"] << "<id2>";

 

Is there a workaround or a better way concatenation a string in groovy?

 

Related question:

 

Thank you

Reply | Threaded
Open this post in threaded view
|

Re: Long String concatenation failed

Jmeter Tea
Thank for your answers, I still have some comments:
mg: I don't want to have a huge line with 20 parameters that can't be seen on screen so I need new lines between parameters
Nelson, Erick: I don't need XML as the article suggest " builder classes to create XML "

On Tue, Sep 25, 2018 at 3:39 PM, Nelson, Erick <[hidden email]> wrote:

No, I mean markup builder.

Mr Haki says it best….

http://mrhaki.blogspot.com/2009/10/groovy-goodness-creating-xml-with.html

 

 

Erick Nelson

Senior Developer – IT

HD Supply Facilities Maintenance

(858) 740-6523

 

 

From: mg <[hidden email]>
Reply-To: "[hidden email]" <[hidden email]>
Date: Tuesday, September 25, 2018 at 5:19 AM
To: "[hidden email]" <[hidden email]>
Subject: Re: Long String concatenation failed

 

If it is just the CTE that is the problem, you just have ro move the "<<" to the end of the previous line... 

 

-------- Ursprüngliche Nachricht --------

Von: Jmeter Tea <[hidden email]>

Datum: 25.09.18 09:56 (GMT+01:00)

Betreff: Long String concatenation failed

 

Hello,
I have to  concatenate a lot of variables in a script and I want to make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unexpected token: << @ line 2, column 1.
   << vars["id2"] << "<id2>"
 
Code:
String text ="<id>" <<vars["id1"] << "<id><id2>" 
<< vars["id2"] << "<id2>";

 

Is there a workaround or a better way concatenation a string in groovy?

 

Related question:

 

Thank you


Reply | Threaded
Open this post in threaded view
|

Re: Long String concatenation failed

ericksn

Your example looked like you were building xml to me

 

Erick Nelson

Senior Developer – IT

HD Supply Facilities Maintenance

(858) 740-6523

 

 

From: Jmeter Tea <[hidden email]>
Reply-To: "[hidden email]" <[hidden email]>
Date: Tuesday, September 25, 2018 at 5:55 AM
To: "[hidden email]" <[hidden email]>
Subject: Re: Long String concatenation failed

 

Thank for your answers, I still have some comments:

mg: I don't want to have a huge line with 20 parameters that can't be seen on screen so I need new lines between parameters

Nelson, Erick: I don't need XML as the article suggest " builder classes to create XML "

 

On Tue, Sep 25, 2018 at 3:39 PM, Nelson, Erick <[hidden email]> wrote:

No, I mean markup builder.

Mr Haki says it best….

http://mrhaki.blogspot.com/2009/10/groovy-goodness-creating-xml-with.html

 

 

Erick Nelson

Senior Developer – IT

HD Supply Facilities Maintenance

(858) 740-6523

 

 

From: mg <[hidden email]>
Reply-To: "[hidden email]" <[hidden email]>
Date: Tuesday, September 25, 2018 at 5:19 AM
To: "[hidden email]" <[hidden email]>
Subject: Re: Long String concatenation failed

 

If it is just the CTE that is the problem, you just have ro move the "<<" to the end of the previous line... 

 

-------- Ursprüngliche Nachricht --------

Von: Jmeter Tea <[hidden email]>

Datum: 25.09.18 09:56 (GMT+01:00)

Betreff: Long String concatenation failed

 

Hello,
I have to  concatenate a lot of variables in a script and I want to make it readable, but I failed to separate lines as in java, The following code doesn't compile due to:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unexpected token: << @ line 2, column 1.
   << vars["id2"] << "<id2>"
 
Code:
String text ="<id>" <<vars["id1"] << "<id><id2>" 
<< vars["id2"] << "<id2>";

 

Is there a workaround or a better way concatenation a string in groovy?

 

Related question:

 

Thank you

 

12