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

  • Home
  • SEARCH
  • 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 5937623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:34:05+00:00 2026-05-22T15:34:05+00:00

I have code which uses the StreamReader to read HTML from a file, then

  • 0

I have code which uses the StreamReader to read HTML from a file, then calls the ReadToEnd() function. The HTML is stored as a string.

Then I call this line of code:

string bookmarksBar = HTMLDoc.Substring(HTMLDoc.IndexOf(">Bookmarks bar</H3>"), HTMLDoc.IndexOf("</DL><p>"));

So what’s happening here is that I want a particular section of the HTML, so I’m using the string Substring method. The first argument is the startIndex, and the second argument is the length.

I am using the IndexOf methods so that this line of code will return a section of text which should be between ">Bookmarks bar</H3>" and "</DL><p>"

And so the end of the returned string should be where "</DL><p>" is found, right?

The problem then is that the string does not end where </DL><p> is found, but ends 323 characters later, at this line (I have inserted four asterisks to illustrate where the returned string ends):

ICON="data:image/png;base64,iVBORw0KGgoAAA****ANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABbklEQVQ4je3RPWuTYQCF4fs875uYKEilOA 

I can’t make sense of why it’s ending here, since the string does not match "</DL><p>" at this point.

So here is a bigger section of the HTML:

jNpXrXKt4WFgn/KY1J1yBg874KWb0Vmr+BSttzgKt3LuBAAAAAElFTkSuQmCC\"></A>\r\n    </DL><p>\r\n    <DT><H3 ADD_DATE=\"1282073650\" LAST_MODIFIED=\"1301438557\">Link 1</H3>\r\n    <DL><p>\r\n        <DT><H3 ADD_DATE=\"1282073650\" LAST_MODIFIED=\"1286905747\">Link2</H3>\r\n        <DL><p>\r\n            <DT><A HREF=\"http://creators.xna.com/en-GB/create_detail#tour_four\" ADD_DATE=\"1282073650\" ICON=\"data:image/png;base64,iVBORw0KGgoAAA"

You can see the "</DL><p>" in the above HTML, so why doesn’t it stop at that point, instead of stopping at “KGgoAAA”?

Any ideas?

Thanks

  • 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-22T15:34:06+00:00Added an answer on May 22, 2026 at 3:34 pm

    You answered your own question.

    the second argument is the length
    

    The second argument is not the endIndex.

    Also, the way you’re calling this, you will end up getting the text ">Bookmarks bar</H3>" in your result. Try this:

    // You could make the part after the + a constant. I'm using s.Length to demonstrate 
    // where the number would come from.
    var startIndex = HTMLDoc.IndexOf(">Bookmarks bar</H3>") + ">Bookmarks bar</H3>".Length;
    var endIndex = HTMLDoc.IndexOf("</DL><p>");
    string bookmarksBar = HTMLDoc.Substring(startIndex, endIndex - startIndex);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which uses the WWW::Mechanize and HTML::TableExtract modules. Everything works
I have code which uses JNDI.The code snippet as as follows: EntityManager createEM(String JNDI
I have some code which I did not originally create that uses _beginthreadex and
I have a piece of code in ANSI C which uses the time.h library
I have some code which collects points (consed integers) from a loop which looks
I have a program written in VB.NET which stops a service that uses file
I have some code which uses recursion in its implementation. The profiler which I'm
I have some code which uses a selector in a loop. This works: document.getElementById(new_grouping_+i).value
I have a code which uses bit-fields declared as follows typedef struct my{ const
I have some fairly generic code which uses preprocessor macros to add a certain

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.