How do I insert a newline into a string using concat()

I’d like to concatenate two strings but separate them with a newline
character, so that if I load the value from a case later and display it to
the user it will be displayed on 2 lines.
I tried something like:
concat(‘First line’,’\n’, ‘Second line’)

but the escaping didn’t work. How should I insert the new line?

Thanks,
Andrew

Hi Andrew,

Two things.

  1. In many cases you’ll actually need two newlines due to the way that our
    text formatter works (it uses “markdown” syntax)
  2. In general you can use the XML escape to insert a newline

-Clayton

··· On Tue, Apr 4, 2017 at 10:40 AM, Andrew Cawood wrote:

I’d like to concatenate two strings but separate them with a newline
character, so that if I load the value from a case later and display it to
the user it will be displayed on 2 lines.
I tried something like:
concat(‘First line’,’\n’, ‘Second line’)

but the escaping didn’t work. How should I insert the new line?

Thanks,
Andrew


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Clayton/Andrew,

I was just testing this and saw interesting behavior. It looks like for it
to work you actually need to type:

concat(“first line”,
"

“,
“second line”,

",
“third line”)

That’s literally just typing the Enter key twice to make newlines instead
of typing " ". When I used " "CommCare would turn those
into spaces when I saved. I’m surprised (and happy) that worked. Is that
expected behavior?

-Nick

Nick Nestle
Technical Project Manager | Dimagi Inc.

··· On Tue, Apr 4, 2017 at 7:52 AM, Clayton Sims wrote:

Hi Andrew,

Two things.

  1. In many cases you’ll actually need two newlines due to the way that our
    text formatter works (it uses “markdown” syntax)
  2. In general you can use the XML escape to insert a newline

-Clayton

On Tue, Apr 4, 2017 at 10:40 AM, Andrew Cawood acawood777@gmail.com wrote:

I’d like to concatenate two strings but separate them with a newline
character, so that if I load the value from a case later and display it to
the user it will be displayed on 2 lines.
I tried something like:
concat(‘First line’,’\n’, ‘Second line’)

but the escaping didn’t work. How should I insert the new line?

Thanks,
Andrew


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hey Nick,

Interesting. I think having the newlines directly in the expression like
that would be expected to work, although I don’t think it’s specifically
"planned for" by the team.

The interplay between what gets encoded (and decoded) to our saved format
can be a bit challenging to keep up with, so my guess is that your newlines
are getting converted into those XML entities then “Decoded” back into
newlines. If it worked differently in the future my guess would be that you
would be presented with " " instead of the newline, so I don’t think
there’s any danger in using that pattern if it’s working.

-Clayton

··· On Thu, Apr 6, 2017 at 1:09 PM, Nick Nestle wrote:

Hi Clayton/Andrew,

I was just testing this and saw interesting behavior. It looks like for it
to work you actually need to type:

concat(“first line”,
"

“,
“second line”,

",
“third line”)

That’s literally just typing the Enter key twice to make newlines instead
of typing " ". When I used " "CommCare would turn
those into spaces when I saved. I’m surprised (and happy) that worked. Is
that expected behavior?

-Nick

Nick Nestle
Technical Project Manager | Dimagi Inc.

On Tue, Apr 4, 2017 at 7:52 AM, Clayton Sims csims@dimagi.com wrote:

Hi Andrew,

Two things.

  1. In many cases you’ll actually need two newlines due to the way that
    our text formatter works (it uses “markdown” syntax)
  2. In general you can use the XML escape to insert a newline

-Clayton

On Tue, Apr 4, 2017 at 10:40 AM, Andrew Cawood acawood777@gmail.com wrote:

I’d like to concatenate two strings but separate them with a newline
character, so that if I load the value from a case later and display it to
the user it will be displayed on 2 lines.
I tried something like:
concat(‘First line’,’\n’, ‘Second line’)

but the escaping didn’t work. How should I insert the new line?

Thanks,
Andrew


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.