Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. string to html tag

string to html tag

Scheduled Pinned Locked Moved C#
csharphtmldata-structuresquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aljaz111
    wrote on last edited by
    #1

    I am working with .net application. I have few informations in string. Now i would like to put this string into html tags. Lets say i have array of names and i would like to write them down in html paragraph. How could i do this in c# code?

    L P K 3 Replies Last reply
    0
    • A Aljaz111

      I am working with .net application. I have few informations in string. Now i would like to put this string into html tags. Lets say i have array of names and i would like to write them down in html paragraph. How could i do this in c# code?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You can use response.write() function to do that.

      string htmltodisp="here is my string to display in paragraph";
      Response.Write("<p>" + htmltodisp + "</p>");

      Hope this will help!

      Jinal Desai - LIVE Experience is mother of sage....

      1 Reply Last reply
      0
      • A Aljaz111

        I am working with .net application. I have few informations in string. Now i would like to put this string into html tags. Lets say i have array of names and i would like to write them down in html paragraph. How could i do this in c# code?

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        It depends how you want to format the data. Suppose for instance that you want each name in a paragraph, a quick and dirty hack to do this would be to use something like:

        StringBuilder sb = new StringBuilder();
        foreach(string name in names)
        {
        sb.AppendFormat("<p>{0}</p>", name);
        }

        Alternatively you could look at the HtmlTextWriter[^] class to do the job properly.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        realJSOPR 1 Reply Last reply
        0
        • P Pete OHanlon

          It depends how you want to format the data. Suppose for instance that you want each name in a paragraph, a quick and dirty hack to do this would be to use something like:

          StringBuilder sb = new StringBuilder();
          foreach(string name in names)
          {
          sb.AppendFormat("<p>{0}</p>", name);
          }

          Alternatively you could look at the HtmlTextWriter[^] class to do the job properly.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          Pete O'Hanlon wrote:

          Alternatively you could look at the HtmlTextWriter[^] class to do the job properly.

          I think he's better off writing it the frist way. What benefit does the HtmlTextWriter have? I diodn't see any, myself.

          .45 ACP - because shooting twice is just silly
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

          P 1 Reply Last reply
          0
          • realJSOPR realJSOP

            Pete O'Hanlon wrote:

            Alternatively you could look at the HtmlTextWriter[^] class to do the job properly.

            I think he's better off writing it the frist way. What benefit does the HtmlTextWriter have? I diodn't see any, myself.

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            I wasn't sure if he was working in an ASP.NET environment. If he is, and he's developing a custom control (again - unsure, so I've gone for the safe case here) then the HtmlTextWriter (and children such as the XhtmlTextWriter) are a good fit.

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            1 Reply Last reply
            0
            • A Aljaz111

              I am working with .net application. I have few informations in string. Now i would like to put this string into html tags. Lets say i have array of names and i would like to write them down in html paragraph. How could i do this in c# code?

              K Offline
              K Offline
              karle
              wrote on last edited by
              #6

              I would use WebUtility.HtmlEncode from System.NET library. It provides a correct encoding of '<','>' and '&' ,... Your html code would have bugs, if your string contains one of the chars and you don't encode them. You can decorate the converted string with html tags.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups