Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6930749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:29:18+00:00 2026-05-27T11:29:18+00:00

in among lots of html source i have some elements like this <option value=15>Bahrain

  • 0

in among lots of html source i have some elements like this

<option value=15>Bahrain - Manama</option>
<option value=73>Bangladesh - Dhaka</option>
<option value=46>Barbados - Bridgetown</option>
<option value=285>Belarus - Minsk</option>
<option value=48>Belgium - Brussels</option>
<option value=36>Belize - Belmopan</option>

Also I have a dictionary declared like Dictionary<string, int> Places = new Dictionary<string, int>();

What I want to do it extract the City name out of the html and put it into of Places, and extract the number code out and put it into the int. For the first one I would add Placed.Add("Manama", 15); The country name can get ignored. The idea though is to scan the html source and add the Cities automatically.

this is what I have so far

string[] temp = htmlContent.Split('\n');
List<string> temp2 = new List<string>();
foreach (string s in temp)
{
    if (s.Contains("<option value="))
    {
        string t = s.Replace("option value=", ""); 
        temp2.Add(t); 
    }
}

This cuts out some of the text but then I more or less get stuck wondering how to extract the relevant parts from the text. It’s really bad I know but I’m learning 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:29:19+00:00Added an answer on May 27, 2026 at 11:29 am

    If the only relevant data you are looking for is within

    string[] options = Regex.Split(theSource, "<option value="); // Splits up the source which is downloaded from the url
    

    that way you are instantly faced with an array of strings with the first few chars being your int. if the ints are always over 10, i.e 2 characters long, you can use:

    int y = 2; // pointer
    string theString = options[x].substring(0,2); // if the numbers are always > 10 its quicker than a loop otherwise leave this bit out and loop the is below
    if(options[x].substring(y,1)!=">") // check to see if the number has finished
    {
        theString += options[x].substring(y,1);
        y++;
    }
    int theInt = int.Parse(theString);
    

    to get the number you can loop the if statement with a pointer if you need to get longer numbers. If the numbers are not always over 10, just loop the if statement with a pointer and ignore the first lines.

    Then I would re-use the string theString:

    string[] place = Regex.Split(options[x], " - "); // split it immediately after the name
    theString = place[0].substring(y, place[0].length - y); 
    

    And then add them with

    Places.Add(theString, theInt);
    

    Shoud work, if the code doesnt work straigth away, the algorithms will, just make sure the spelling is right and that the variables are doing what they should

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have lots of code like this: FileStream fs = File.Open(@C:\Temp\SNB-RSS.xml, FileMode.Open); using (XmlTextReader
Say I have an HTML form like this to collect an email from a
With lots of talk and bickering among developers about how IE breaks standards, is
Encoding issues are among the one topic that have bitten me most often during
I work on a parallel build tool which builds (among lots of other things)
We have seen lots of discussion in SO regarding the class vs struct in
I have quite a big amount of fixed size records. Each record has lots
I'm learning WPF and MVVM and trying to stress good design. I have lots
I have an HTML text input where users can write in a name for
This is a simplification of the issue (there are lots of ways of doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.