Add newline while concatenating strings

Description
nikhila
Posts: 5
Joined: Thu Jan 28, 2016 5:52 pm

Add newline while concatenating strings

Postby nikhila » Wed Jun 08, 2016 11:05 pm

Hi,

I am working on a custom script using classic WIKI pages where I need to iterate through serval custom text fields and prepare a concatenated text. I also need each field value to be in a new line.

After searching through several posts I came to this code:

Code: Select all

VelocityContext ctx = new VelocityContext();
ctx.put("newline", "\n");
#set($strResult="$strResult $newline ASIC:$text")

Unfortunately this didn't work either.

Any ideas?
~Nik

nikhila
Posts: 5
Joined: Thu Jan 28, 2016 5:52 pm

Re: Add newline while concatenating strings

Postby nikhila » Mon Jun 13, 2016 8:45 pm

Update:
I tried using the escape tool as well and no luck.

Code: Select all

$escapeTool.newline
$escapeTool.n

Interestingly I can use the escape tool to add a $ sign:

Code: Select all

$escapeTool.d

Any pointers would be appreciated.

Thanks
~Nik

Harou33
Posts: 10
Joined: Wed Apr 04, 2018 10:40 am

Re: Add newline while concatenating strings

Postby Harou33 » Thu Jun 14, 2018 11:32 am

<br/>

Enoriel
Posts: 2
Joined: Tue Mar 19, 2019 1:12 pm

Re: Add newline while concatenating strings

Postby Enoriel » Tue Mar 19, 2019 2:16 pm

Hello,
Double-blackslash is interpreted as newline.
For example, I use this piece of code to shorten a long description (html or plain-text) to its first sentence. Items 2 and 3 of the foreach loop allow searching for periods or colons followed by a newline.

Code: Select all

#set($shortText = $longText)
#foreach ($delimiter in [". ", ".\\", ":\\", "<br", "<ul", "<ol", "</p", "<table"])
   #set($delimiterIdx = $shortText.indexOf($delimiter))
   #if($delimiterIdx != -1)
      #set($shortText = $shortText.substring(0, $delimiterIdx))
   #end
#end


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 8 guests