how do you create a class to read the html body and phase it into a variable?
Example the page http://domain.com/page1.aspx
display the following plaintext within the html body content
item1=xyz&item2=abc&item3=jkl
how do you read content of the html body and assign them to a variables
in this case
variable1=xyz (value taken from item1=)
variable2=abc (value taken from item2=)
variable3=jkl (value taken from开发者_Python百科 item3=)?
It is a two step process.
First you need to get body contents.
Second you need to parse content and assign to variables.
Getting body content code look like this:
Regex exp = new Regex(@"((?:.(?!<body[^>]*>))+.<body[^>]*>)|(</body\>.+)", RegexOptions.IgnoreCase);
string InputText = content;
string[] MatchList = exp.Split(InputText);
string body = MatchList[2];
Parsing code looks like:
string body = content;
string [] param = {"&"};
string[] anotherParam = { "=" };
string[] str = body.Split(param , StringSplitOptions.RemoveEmptyEntries);
System.Collections.Hashtable table = new System.Collections.Hashtable();
foreach (string item in table)
{
string[] arr = item.ToString().Split(anotherParam, StringSplitOptions.RemoveEmptyEntries);
if(arr.length != 2)
continue;
if(!table.Contains(arr[0])){
table.Add(arr[0], arr[1]);
}
}
I think you mean query string but not html body. In that case you can use ASP.NET Page class's property Context as follows
string var1 = Context.Request.QueryString["item1"];
精彩评论