Question: I have the following String which is coming from the backend and I need to format the string before showing it in the alert message.

How we can do that using Apex code or using JavaScript code? How we can put `\n` for each `.`, `•` and `o`?

> 
> Try adding the above to your web page, then load the page and see if it works. If it doesn't, you probably have a bug. Specifically, please:  • Be sure you typed everything exactly as it appears,:    o Third Party Details   • Upload the following documents in the Requestor Required Documentation section:    o Proposal    o Relevant Documentation
> 
> 
> 

I am using Visualforce pages and Controller.

```
    <!DOCTYPE html>
    <html>
    <body>

    <h2>JavaScript Alert</h2>

    <button onclick="myFunction()">Try it</button>

    <script>
    function myFunction() {
        alert("Try adding the above to your web page, then load the page and see if it works. 
If it doesn't, you probably have a bug.\n Specifically, please:\n   
• Be sure you typed everything exactly as it appears,:\n     
o Third Party Details   \n• Upload the following documents in the Requestor
Required Documentation section:      \no Proposal     \no Relevant Documentation");
    }
    </script>

</body>
</html>

```

I have already formatted code using `object.field.stripHtmlTags();`

Shown alert should be like below. But how to split String for `.`, `•` and `o` and add \n using apex?
[![enter image description here](https://i.stack.imgur.com/Qi6pi.png)](https://i.stack.imgur.com/Qi6pi.png)

Answer: 
Try this

```js
alert("Try adding the above to your web page, then load the page and see if it works. If it doesn 't, you probably have a bug.\n\n Specifically, please:\n\no Be sure you typed everything exactly as it appears,: \no Third Party Details\no Upload the following documents in the Requestor Required Documentation section: \no Proposal\ no Relevant Documentation ");
```

Or Try this

```js
alert("Try adding the above to your web page, then load the page and see if it works. If it doesn 't, you probably have a bug." + "\n\n Specifically, please:" + "\n\no Be sure you typed everything exactly as it appears" + "\no Third Party Details" + "\no Upload the following documents in the Requestor Required Documentation section" + "\no Proposal" + "\no Relevant Documentation ");
```

This is edited code according to your updated post with image

```js
alert("Try adding the above to your web page, then load the page and see if it works. If it doesn 't, you probably have a bug."+"\n\n Specifically, please:"+"\n\n• Be sure you typed everything exactly as it appears"+ "t\no Third Party Details"+"\n• Upload the following documents in the Requestor Required"+"\n Documentation section" +"\no Proposal"+"\no Relevant Documentation ");
```
You can try by using javascript [replace function](https://www.w3schools.com/jsref/jsref_replace.asp "replace function")

for example :

```js
    var str = "Try adding the above to your web page, then load the page and see if it works. If it doesn't works";
    var newStr = str.replace(".", '.\n');
    alert(newStr);
```