1

I am getting issues to convert unicode and render in a nice HTML code.

Here is the information i have as an input in my Json file

`"CLIENT:\r\n-Client1: Project1\u00c2\u00a0\r\n- Client2: etc..."`

I would like this to render as below in

CLIENT: - client1: Project 1 - Client2: etc...

It currently renders like this :

`CLIENT: - Client1: Project1Â  - Client2: etc...`

I looked everywhere but could not find a function that could handle all unicodes to decode in nice html code. Thanks in advance!

suiram85
  • 19
  • 3

3 Answers3

1

Maybe you can take a look at this: How do I replace all line breaks in a string with
tags?

You do this:

str = str.replace(/(?:\r\n|\r|\n)/g, '<br />');

before insert into the html.

Community
  • 1
  • 1
Tan Li Hau
  • 1,984
  • 17
  • 24
0

If you are using javascript, you can use this fragment

<script>
var c = decodeURIComponent(escape(`"CLIENT:\r\n-Client1: Project1\u00c2\u00a0\r\n- Client2: etc..."`));
   c = c.replace(/(?:\r\n|\r|\n)/g, '');
   c = c.replace(':-', ': - ');
   document.write(c);
</script>
Jose Bernalte
  • 177
  • 1
  • 10
0

Ok I managed to make this work with the below function:

function strFormat(str) {
    var c= decodeURIComponent(escape(str));
    c= c.replace(/(?:\r\n|\r|\n)/g, '<br />');
    c= c.replace(':-', ': - ');
    return c;

}

Let me know if there are any cleaner way to do this?

suiram85
  • 19
  • 3