Okay so I’m running into an issue and none of it makes sense to me. I’m not an ASP person or really know anything about the language, but an extremely old site at work has broken an i’ve been charged with fixing it.
So basically I have a variable that is a string. that comes from a web stream. For events.
string thisEvent = events.Substring(startAt, stopAt + 4);
If you write the thisEvent variable to the stage it ouputs the following.
<p><pause>Today! <br><a href="HTTP://SUSQUEHANNAVALLEYPACOC.WEBLINKCONNECT.COM/CWT/EXTERNAL/WCPAGES/WCEVENTS/EventDetail.aspx?EventID=1288"><b>Programs and Development Committee </b></a><br>Time: 8:30 AM to 9:30 AM<br></p>
Now I need to create a bunch of variables based off of this long string so I’ve been trying to use Substring.
For my first variable I need to get the value thats between the pause tag and the br. So for the above text that value would be “Today!”
So I did this.
string when = thisEvent.Substring(10, (thisEvent.IndexOf("<br>") - 1));
This however gives me an error saying startIndex cannot be larger than length of string.
Parameter name: startIndex
I don’t understand how I’m getting this error since the “thisEvent” variable is much longer then 10 characters.
So you can see all the code as a whole I placed it below. Thanks for the help I’m going to go insane looking at this.
WebRequest req = WebRequest.Create("http://susquehannavalleypacoc.weblinkconnect.com/cwt/External/WCPages/WCEvents/eventscrollinglist.aspx");
WebResponse resp = req.GetResponse();
Stream s = resp.GetResponseStream();
StreamReader sr = new StreamReader(s, Encoding.ASCII);
string events = sr.ReadLine();
/* PATTERN
<p><pause>WHEN<br>DATE<br><a href="LINK"><b>TITLE</b></a><br>Time: TIME<br></pause</p>
FIRST RESPONSE
<p><pause>Today! <br><a href="HTTP://SUSQUEHANNAVALLEYPACOC.WEBLINKCONNECT.COM/CWT/EXTERNAL/WCPAGES/WCEVENTS/EventDetail.aspx?EventID=1288"><b>Programs and Development Committee </b></a><br>Time: 8:30 AM to 9:30 AM<br></p>
*/
int eventCount = 0;
string[,] myEvents = new string[5, 2]; //0=WHEN; 1=DATE; 2=LINK; 3=TITLE; 4=TIME
do
{
int startAt = events.IndexOf("<p>");
int stopAt = events.IndexOf("</p>");
string thisEvent = events.Substring(startAt, stopAt + 4);
events = events.Substring(stopAt + 4);
string when = thisEvent.Substring(10, (thisEvent.IndexOf("<br>") - 1));
}