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
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.
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.
Alternate between single and double quotes. For example, to add double quotes to a string, wrap the string in single quotes.
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.
so if you have:
def list = ['one', 'two', 'three']
Then you can do:
List modifiedList = list.collect{ '"' + it + '"'}
output : ["one", "two", "three"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With