We help IT Professionals succeed at work.
Get Started

parse portion of HTML - count of certain tag - C# RegEx code needed

Tom Knowlton
Tom Knowlton asked
Last Modified: 2012-05-12
This section of the HTML is of interest to me:

<select name="ctl00$ContentPlaceHolder1$dlStore" id="ctl00_ContentPlaceHolder1_dlStore" disabled="disabled" title="Store" style="text-align: left">
            <option value="NULL">Select Campus...</option>
            <option selected="selected" value="1">KSU ASHTABULA</option>

This will be surrounded by other HTML, but it is just this block of code that I want to extract and examine.

Within this block of code, above, I want to check for HOW MANY <option></option> pairings there are.  If there is only one I want to do one thing.  If there are more than one I want to do another thing.

So the logic would be:

(A) Isolate the portion of code above.  Perhaps use the existence of "dlStore" in the id to identifiy the <select></select> block
(B) in this block of code we isolate in (A), count how many times there is an <option></option> pairing.
(C) do something based on the count.

Please provide tested working C# source code if you can.

I am using C# in a windows app to do this....I will favor a working C# .NET response over something more generic.
Watch Question
Most Valuable Expert 2011
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE