basically what i am doing is building a c# app which allows users to open up html files and in between the certain tags find the contents.

So it has to:
- read start tag, example: <object>
- read stop tag, example: </object>
- take text which is in between the two tags and place it in a
text area.
any ideas???

10 Years
Discussion Span
Last Post by scru

psuedocode time!

assuming tag opener is "<" and tag closer is ">" and wanted tag is [any tag you want to read the contents of]
Read every character as 'c':
  if c is tag opener:
    read d from c until d is tag closer
    if string(c+, d) is wanted_tag:
      read e from d until e s tag opener:
      return string(d+, e)

Of course, you can do some extra checking on that last part to make sure the encountered tag is actually the closer for your wanted tag, and not just some random < or a tag opener for a nested tag.


Yes that is the problem seeing if there are other tags in the text i want
I know how to get to a tag and parsing the value of that tag, but i am still getting confused what to do when one of the characters is '<' which belongs to a different tag


That's a design decision that you have to make. Do you skip over those internal tags, do you complain to the user, or do you return the text as is?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.