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. Removing an element from the content of a string value which is HTML code

Removing an element from the content of a string value which is HTML code

Scheduled Pinned Locked Moved C#
html
4 Posts 2 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.
  • F Offline
    F Offline
    Farhad Eft
    wrote on last edited by
    #1

    Hi, I have a string variable which the value is html code. I like to check to see if certain word (in this case EEST) exist in the first

    element as you can see in the sample. Then I like to remove that element and its content from the string.

    Some text here, 26 APRIL 2017 AT 9:00 AM EEST. some other content here as well>

    much other elements here as well

    then the output becomes:

    much other elements here as well

    I was wondering, how I can do such task. Thank you.

    OriginalGriffO 1 Reply Last reply
    0
    • F Farhad Eft

      Hi, I have a string variable which the value is html code. I like to check to see if certain word (in this case EEST) exist in the first

      element as you can see in the sample. Then I like to remove that element and its content from the string.

      Some text here, 26 APRIL 2017 AT 9:00 AM EEST. some other content here as well>

      much other elements here as well

      then the output becomes:

      much other elements here as well

      I was wondering, how I can do such task. Thank you.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Try a regex:

      public static Regex regex = new Regex(
      "\\<p\\sclass=\"myclass\"\\>.*?\\sEEST.*?\\>\\</p\\>",
      RegexOptions.IgnoreCase
      | RegexOptions.CultureInvariant
      | RegexOptions.IgnorePatternWhitespace
      | RegexOptions.Compiled
      );

      Then just use Replace:

      string result = regex.Replace(inputText,"");

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      F 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Try a regex:

        public static Regex regex = new Regex(
        "\\<p\\sclass=\"myclass\"\\>.*?\\sEEST.*?\\>\\</p\\>",
        RegexOptions.IgnoreCase
        | RegexOptions.CultureInvariant
        | RegexOptions.IgnorePatternWhitespace
        | RegexOptions.Compiled
        );

        Then just use Replace:

        string result = regex.Replace(inputText,"");

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        F Offline
        F Offline
        Farhad Eft
        wrote on last edited by
        #3

        You are amazing! Thanks! :)

        OriginalGriffO 1 Reply Last reply
        0
        • F Farhad Eft

          You are amazing! Thanks! :)

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          You're welcome!

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          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