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. Handle string

Handle string

Scheduled Pinned Locked Moved C#
csharphtmlhelptutorialquestion
3 Posts 3 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.
  • R Offline
    R Offline
    rockxuyenmandem
    wrote on last edited by
    #1

    How can i do to replace Html Tag For example in my project when i input <br> or <p> the error message will display Could you can write an function in C# to replace the HTML Tag Thanks for helping. I tried so hard and got so far

    M C 2 Replies Last reply
    0
    • R rockxuyenmandem

      How can i do to replace Html Tag For example in my project when i input <br> or <p> the error message will display Could you can write an function in C# to replace the HTML Tag Thanks for helping. I tried so hard and got so far

      M Offline
      M Offline
      MoustafaS
      wrote on last edited by
      #2

      You can make a function that replaces all the ( < ) tags with (_&_l_t_;_)(<) and the closing tag( > ) with (_&_g_t_;_). (>) Note: You must remove the underscore character (_) from all the codes.

      1 Reply Last reply
      0
      • R rockxuyenmandem

        How can i do to replace Html Tag For example in my project when i input <br> or <p> the error message will display Could you can write an function in C# to replace the HTML Tag Thanks for helping. I tried so hard and got so far

        C Offline
        C Offline
        Carsten Zeumer
        wrote on last edited by
        #3

        If you need an HTML-Encoded string you can use the System.Web.HttpUtility.HtmlEncode function. You must reference the System.Web assembly to use this function. If you need to actually strip the Html tags you coud use a regular expression like this: // replace br an p tags with linefeed string cleanedText = System.Text.RegularExpressions.Regex.Replace(htmlString,@"(?:]*>)","\r\n"); // remove tags cleanedText = System.Text.RegularExpressions.Regex.Replace(cleanedText,@"(?:<[/!]?([A-Z][A-Z0-9]*)[^>]*>)",""); This code is very basic. It will not strip scripts nor will it handle tables pretty well. I hope this is at least a start for you.

        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