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

**URL:** <https://forum.dimagi.com/t/how-do-i-insert-a-newline-into-a-string-using-concat/3402>\
**Category:** Users\
**Created:** [April 4, 2017, 2:40pm UTC](https://forum.dimagi.com/t/how-do-i-insert-a-newline-into-a-string-using-concat/3402 "2017-04-04T14:40:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Cawood](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/andrew_cawood/32/515_2.png) [@Andrew\_Cawood](https://forum.dimagi.com/u/Andrew_Cawood)\
**Post date:** [April 4, 2017, 2:40pm UTC](https://forum.dimagi.com/t/how-do-i-insert-a-newline-into-a-string-using-concat/3402/1 "2017-04-04T14:40:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Clayton\_Sims](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/clayton_sims/32/496_2.png) [@Clayton\_Sims](https://forum.dimagi.com/u/Clayton_Sims)\
**Post date:** [April 4, 2017, 2:52pm UTC](https://forum.dimagi.com/t/how-do-i-insert-a-newline-into-a-string-using-concat/3402/2 "2017-04-04T14:52:05Z")

</div>

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](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Nick\_Nestle](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/n/46a35a/32.png) [@Nick\_Nestle](https://forum.dimagi.com/u/Nick_Nestle)\
**Post date:** [April 6, 2017, 5:09pm UTC](https://forum.dimagi.com/t/how-do-i-insert-a-newline-into-a-string-using-concat/3402/3 "2017-04-06T17:09:15Z")

</div>

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](mailto: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](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](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](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Clayton\_Sims](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/clayton_sims/32/496_2.png) [@Clayton\_Sims](https://forum.dimagi.com/u/Clayton_Sims)\
**Post date:** [April 6, 2017, 5:32pm UTC](https://forum.dimagi.com/t/how-do-i-insert-a-newline-into-a-string-using-concat/3402/4 "2017-04-06T17:32:21Z")

</div>

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](mailto: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](mailto: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](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/d/optout](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](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](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](mailto:commcare-users+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
