S
Steffan A. Cline
I am working on some maintenance coding and am stuck. This program that was
written parses web pages and downloads the files somewhat like a crawler.
The code is like this in it's original form.
// get form view state and event validation
int viewstateIndex = content.IndexOf("id=\"__VIEWSTATE\"") + 24;
int viewstateEndIndex = content.IndexOf("\" />", viewstateIndex);
_viewstate = HttpUtility.UrlEncodeUnicode(content.Substring(viewstateIndex,
viewstateEndIndex - viewstateIndex));
I am thinking it should look more like this to be reliable but I am unsure
of how to use the $1 syntax to extract the contents of the match.
Match _viewstateValue = Regex.Match(content, "<input .*?id=\"__VIEWSTATE\"
..*?value=\"([^\"].*)");
_viewstate = HttpUtility.UrlEncodeUnicode(_viewstateValue.ToString());
int eventIndex = content.IndexOf("id=\"__EVENTVALIDATION\"") + 30;
int eventEndIndex = content.IndexOf("\" />", eventIndex);
_eventvalidation =
HttpUtility.UrlEncodeUnicode(content.Substring(eventIndex, eventEndIndex -
eventIndex));
And again... I tried but I need to use the $1 syntax to get the value in the
middle and not the whole string.
Match _eventvalidationValue = Regex.Match(content, "<input
..*?id=\"__EVENTVALIDATION\" .*?value=\"([^\"].*)");
_eventvalidation =
HttpUtility.UrlEncodeUnicode(_eventvalidationValue.ToString());
Obviously the string chopping will work but regexp seems more stable as far
as flexibility etc. Anyone have any suggestions on these?
Thanks,
Steffan
written parses web pages and downloads the files somewhat like a crawler.
The code is like this in it's original form.
// get form view state and event validation
int viewstateIndex = content.IndexOf("id=\"__VIEWSTATE\"") + 24;
int viewstateEndIndex = content.IndexOf("\" />", viewstateIndex);
_viewstate = HttpUtility.UrlEncodeUnicode(content.Substring(viewstateIndex,
viewstateEndIndex - viewstateIndex));
I am thinking it should look more like this to be reliable but I am unsure
of how to use the $1 syntax to extract the contents of the match.
Match _viewstateValue = Regex.Match(content, "<input .*?id=\"__VIEWSTATE\"
..*?value=\"([^\"].*)");
_viewstate = HttpUtility.UrlEncodeUnicode(_viewstateValue.ToString());
int eventIndex = content.IndexOf("id=\"__EVENTVALIDATION\"") + 30;
int eventEndIndex = content.IndexOf("\" />", eventIndex);
_eventvalidation =
HttpUtility.UrlEncodeUnicode(content.Substring(eventIndex, eventEndIndex -
eventIndex));
And again... I tried but I need to use the $1 syntax to get the value in the
middle and not the whole string.
Match _eventvalidationValue = Regex.Match(content, "<input
..*?id=\"__EVENTVALIDATION\" .*?value=\"([^\"].*)");
_eventvalidation =
HttpUtility.UrlEncodeUnicode(_eventvalidationValue.ToString());
Obviously the string chopping will work but regexp seems more stable as far
as flexibility etc. Anyone have any suggestions on these?
Thanks,
Steffan