Simple text to HTML conversion

前端 未结 6 721
醉梦人生
醉梦人生 2021-01-04 07:33

I have a very simple asp:textbox with the multiline attribute enabled. I then accept just text, with no markup, from the textbox. Is there a comm

6条回答
  •  借酒劲吻你
    2021-01-04 08:11

    I know this is an old post, but I've recently been in a similar problem using C# with MVC4, so thought I'd share my solution.

    We had a description saved in a database. The text was a direct copy/paste from a website, and we wanted to convert it into semantic HTML, using

    tags. Here is a simplified version of our solution:

    string description = getSomeTextFromDatabase();
    foreach(var line in description.Split('\n')
    {
        Console.Write("

    " + line + "

    "); }

    In our case, to write out a variable, we needed to prefix @ before any variable or identifiers, because of the Razor syntax in the ASP.NET MVC framework. However, I've shown this with a Console.Write, but you should be able to figure out how to implement this in your specific project based on this :)

提交回复
热议问题