Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add double quotes to list of strings

Tags:

groovy

I've got a list in groovy lets say:

[one, two, three]

Now I want to add double quotes to the strings of this array so that the final result would be:

["one", "two", "three"]

Note that I do want the square brackets to be included as well. How can I do that in Groovy in the most comprehensive way?

EDIT: I'm using groovy templating inside html code and I just want a string in the exact format I described above

like image 332
ThanosFisherman Avatar asked Sep 21 '16 09:09

ThanosFisherman


People also ask

How do you add a double quote to a string array?

If you want to add double quotes(") to String, then you can use String's replace() method to replace double quote(") with double quote preceded by backslash(\"). Here is an example.

How do you display double quotes in a string?

To place quotation marks in a string in your code In Visual C# and Visual C++, insert the escape sequence \" as an embedded quotation mark.

How do you add quotes to a list in Python?

Alternate between single and double quotes. For example, to add double quotes to a string, wrap the string in single quotes.

How do you add double quotes to a string in Python?

To quote a string in Python use single quotation marks inside of double quotation marks or vice versa. For instance: example1 = "He said 'See ya' and closed the door." example2 = 'They said "We will miss you" as he left.


1 Answers

so if you have:

def list = ['one', 'two', 'three']

Then you can do:

List modifiedList = list.collect{ '"' + it + '"'}

output : ["one", "two", "three"]

like image 116
Prakash Thete Avatar answered Oct 03 '22 14:10

Prakash Thete