I’m developing an app where at some point app receives a string from Facebook Graph API.
String looks like that:
"Some text some text, some text.nnMore text and morennAnd little bit more".
How can I replace nn with line break what actually works in code?
I know how to replace this with something:
var ret = stringToReplace.replace('nn','<br />');
But how can i replace it with working line break. I have tried to replace with ‘n’ ‘rn’. Every replacement just acts like usual text. For example:
"Some text some text, some text.<br />More text and more<br />And little bit more"
4
Answers
I test the following code and it works. You should just wrap your text in a
<Text>
component.The result of this code is like this:
I know I am pretty late to the party but I recently stumble across the same problem when I was fetching data with
n
from a database. The solution that worked for me was just to run thereplace
method and replace incomingn
with jsxn
. So in your case it would be:Looks like a really stupid solution but it worked for me.
React/ React native has line break object
{`n`}
, see below code sampleUse template literals/backticks as wrapper instead of double-quotes. It worked for me.