0

I have this (portion of) email:

u003cDIV\u003e\n \u003cP STYLE=\"text-align: LEFT; \"\u003e\n \u003cFONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"/\u003e\n \u003c/P\u003e\n \u003cP STYLE=\"text-align: LEFT; \"\u003e\n \u003cFONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"/\u003e\n \u003c/P\u003e\n \u003cP STYLE=\"text-align: LEFT; \"\u003e\n \u003cFONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"\u003eHello Ms. Goodman,

How can I do to format this kind of text and show him to final user as HTML Formatted?

Thanks!

2
  • at first glance, it looks like a lot of these are unicode characters and it also looks like what you posted is incomplete. you'll want to read the string in and convert the unicode at which point I'm guessing it will already be an html string Commented Mar 3, 2017 at 20:42
  • Sorry for posting just a portion but it's kind of confidential the content of that email, but thanks for the idea! Commented Mar 3, 2017 at 20:45

2 Answers 2

0

Well, first of all you are missing an opening \ (probably lost in a copy/paste). but basically, create an html element to hold it:

<div id="message"></div>

then load the string into a javascript string:

var str = '\u003cDIV\u003e\n \u003cP STYLE=\"text-align: LEFT; \"\u003e\n \u003cFONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"/\u003e\n \u003c/P\u003e\n \u003cP STYLE=\"text-align: LEFT; \"\u003e\n \u003cFONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"/\u003e\n \u003c/P\u003e\n \u003cP STYLE=\"text-align: LEFT; \"\u003e\n \u003cFONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"\u003eHello Ms. Goodman,';

and finally push it into the container using jQuery:

$('#message').html(str);

I'm not sure how this is coming in from the server so I can't advise you on that, but this basic idea should work.

The result of your string is

<div>
   <p style="text-align: LEFT; ">
      <font style="letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; "></font>
   </p>
   <p style="text-align: LEFT; ">
      <font style="letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; "></font>
   </p>
   <p style="text-align: LEFT; ">
      <font style="letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; ">Hello Ms. Goodman,</font>
   </p>
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

Use either HttpUtility or WebUtility (depending on whether you want a dependency on System.Web).

Here's a unit test (using NUnit) showing how it would work:

using System.Net;
using NUnit.Framework;

[TestFixture]
public class UnitTest1
{
    [Test]
    public void TestMethod1()
    {
        string original = "\u003cDIV\u003e\n \u003cP STYLE=\"text-align: LEFT; \"\u003e\n \u003cFONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"/\u003e\n \u003c/P\u003e\n \u003cP STYLE=\"text-align: LEFT; \"\u003e\n \u003cFONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"/\u003e\n \u003c/P\u003e\n \u003cP STYLE=\"text-align: LEFT; \"\u003e\n \u003cFONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"\u003eHello Ms. Goodman,";
        string expected = "<DIV>\n <P STYLE=\"text-align: LEFT; \">\n <FONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"/>\n </P>\n <P STYLE=\"text-align: LEFT; \">\n <FONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \"/>\n </P>\n <P STYLE=\"text-align: LEFT; \">\n <FONT STYLE=\"letter-spacing: 0pt; color: #0B333C; font-size: 10pt; font-family: verdana; \">Hello Ms. Goodman,";
        string actual = null;

        actual = WebUtility.HtmlDecode(original);

        Assert.AreEqual(expected, actual);
    }
}

2 Comments

I have something like this: ` @foreach (var item in Model) { var body = item.BodyHTML; var stepa = System.Web.HttpUtility.HtmlDecode(body.ToString()); @Html.Raw(stepa) }` Is there something wrong? Always return the same string.
You would need to put a breakpoint on the controller action and see what you're actually providing to the view. There's no way to say what the problem is based on that snippet (it should work).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.