Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to replace value with linebreak and show it in b-modal (with linebreaks)

I’m working with BootstrapVue.

I have a string like following: Hello / my name / is B0BBY / how / are you ?

Now I want to show this string in a <b-modal> and replace all / (Slash) with a linebreak.. I’ve tried following:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

var newString = actualString.replaceAll(" / ", "\n")

If I console.log this newString it shows in my console with a linebreak. But if I’m using it in my b-modal it shows not with a linebreak, it’s all in one line.

I think there is a pretty simple solution for it, but I can’t figure it out. Thanks for helping me out!

>Solution :

There are two possibilities. If you want to use \n in your HTML, you have to set a CSS property white-space: pre-line; for the parent element.

Or you can simply replace \n with <br>.
Both are possible.

var newString = actualString.replaceAll(" / ", "<br>")

actualString = "Hello / my name / is B0BBY / how / are you ?";
var newString = actualString.replaceAll(" / ", "\n")
console.log(newString)

document.getElementById('out').innerHTML = newString;
<div id="out" style="white-space: pre-line; "></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading