473,414 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Weird Substring Error

Hey all. I'm doing a very basic screen scrape of a page that displays
a banner ad. It is basically an <Atag and an <IMGtag. I need to
grab the url of each and store them.

Right now I can download the page fine into my code but I'm having a
problem on this line:

imgTag = m_strSite.Substring(imageStart, imageEnd);

I get the following error:

Index and length must refer to a location within the string. Parameter
name: length

the strange thing is when I use Substring and use a start value greater
than 5 I get the error.
Here is my code:

private string m_strSite;

private void Page_Load(object sender, System.EventArgs e)
{

string currURL = "http://someurl.com?vars";
m_strSite = OpenSite(currURL);
int imageStart;
int linkStart = 0;
int linkEnd;
int imageEnd = m_strSite.Length - 6 ;
string urlTag;
string imgTag;

imageStart = Find("<img", 0);
linkEnd = imageStart;
urlTag = m_strSite.Substring(linkStart, linkEnd);
imgTag = m_strSite.Substring(imageStart, imageEnd);

}

private int Find(string strSearch, int nStart)
{
return m_strSite.IndexOf(strSearch, nStart);
}

Oct 23 '06 #1
1 1195
<rh******@gmail.comwrote:
Hey all. I'm doing a very basic screen scrape of a page that displays
a banner ad. It is basically an <Atag and an <IMGtag. I need to
grab the url of each and store them.

Right now I can download the page fine into my code but I'm having a
problem on this line:

imgTag = m_strSite.Substring(imageStart, imageEnd);

I get the following error:

Index and length must refer to a location within the string. Parameter
name: length

the strange thing is when I use Substring and use a start value greater
than 5 I get the error.
Substring doesn't take a start index and an end index - it takes a
start index and a *length*.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Mantoulidis | last post by:
PROBLEM: I'm having some weird problems with string::find() (in ParamGenerate()), but since I'm not sure if that is the source of all bad output in my program, I'm posting least code that's...
2
by: Jorge | last post by:
Hello I have been for the last 2 days for abnormal behavior when try to refresh a datagrid from another form. If Not (fenc Is Nothing) Then '' Actualiza a datagrid2 do formenc ...
2
by: Michele Fondry via .NET 247 | last post by:
hello. I have a webform form app in vb.Net that uses a SQL query. I am trying to use the substring function, but get the following error: Description: An unhandled exception occurred during the...
5
by: btober | last post by:
I can't seem to get right the regular expression for parsing data like these four sample rows (names and addresses changed to ficticious values) from a text-type column: Yolanda Harris, 38, of...
2
by: David Filion | last post by:
Hi, I have a question about substring(), when I run the following query: prepaid=# select substring('15148300', 0, 5); substring ----------- 1514 (1 row)
15
by: lucky | last post by:
Hi Guys You are probably my last chance to avoid getting crazy To help you understand my problem I have put images online showing the issue I have: http://www.australix.net/images/pb I...
3
by: =?Utf-8?B?dmluY2VudHc1Ng==?= | last post by:
I have an ASP.NET 2.0 application. It is pretty basic. What it does is shows a gridview of data from a stored procedure. The user can also select a date filter. The problem is that sometimes an...
11
by: dyc | last post by:
how do i make use of substring method in order to extract the specified data from a a long string? I also need to do some checking b4 extracting the data, for instance: it only will extract the...
8
by: JJ | last post by:
This is slightly OT but .... When testing why my aspx page isn't returning the data as expected I decided to type directly into one of my SQL tables. (The column definitions are below). When...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.