string - C# split with StringReader -


i have little problem method . first load html web hardware. little tinny : here code web:

<!doctype html>  <html>  <head>      <title></title>  	<meta charset="utf-8" />  </head>  <body>      <p>001;20151006;0000;1800;1000;999;1;</p>      <p>001;20151006;0100;1300;990;999;1;</p>      <p>001;20151006;0200;1100;1000;999;1;</p>      <p>001;20151006;0300;1500;1100;999;1;</p>      <p>001;20151006;0400;2200;500;999;1;</p>      <p>001;20151006;0500;1900;100;999;1;</p>      <p>001;20151006;0600;0700;990;999;1;</p>      <p>001;20151006;0700;0300;998;999;1;</p>    </body>  </html>

i need take body , load second , 3th row yyyymmdd hh:mm. here code to this:

 char[] pommidchar = { ';' }; webrequest request = webrequest.create(               "http://localhost:49443/wyniki.html");          request.credentials = credentialcache.defaultcredentials;          webresponse response = request.getresponse();        console.writeline(((httpwebresponse)response).statusdescription);          stream datastream = response.getresponsestream();          streamreader reader = new streamreader(datastream);          string responsefromserver = reader.readtoend();          //  console.writeline(responsefromserver);          htmlagilitypack.htmldocument doc = new htmlagilitypack.htmldocument();         doc.loadhtml(responsefromserver);         // console.writeline(doc);            string formatstring = "yyyymmddhhmm";//201510060000;         reader.close();//   = "201510060000"         response.close();         string[] slowa;          string tekst ;         foreach (htmlnode node in doc.documentnode.selectnodes("//body"))         {              string temp = "";             console.writeline(node.innertext);             id = node.innertext;             tekst = node.innertext;             //console.writeline("node"+node.tostring());             slowa = id.split(pommidchar);             temp = slowa[1] + slowa[2];             //console.writeline(slowa[30]);             console.writeline("string pobrany ze strony"+temp);             datetime dt = datetime.parseexact(temp, formatstring, cultureinfo.invariantculture,                                     datetimestyles.none);              console.writeline("ostatnia dana z parse:" + dataparse1.tostring("yyyy-mm-dd hh:mm"));             console.writeline("aktualna pobrana z urzadzenia:" + dt.tostring("yyyy-mm-dd hh:mm")); 

} in tekst have string //body want read line line , copmare date :

using (stringreader readerr = new stringreader(tekst))         {             string[] splitline;             string line;              while ((line = readerr.readline()) != null)             {                 console.writeline(line);                 splitline = line.split(pommidchar);                //  console.writeline(splitline[0]);                 console.writeline(splitline[1]);              }             readerr.close();         } 

but , here clue .i have 1 string in "splitstring" 001 . can describe me others string line? work slowa = id.split(pommidchar); work , split exacly want can`t read line line .

i pass question becuse done. have 1 more stupid question someone. dr university change soruce code web. variables (html code) set in 1 row licke

<body>      <pre><br>001;20151006;000034;1800;1000;999;1<br>001;20151006;000035;1800;1000;999;1;<br>001;20151006;000036;1800;1000;999;1;</pre>  </body>

so , how can take string br tag . solution take them in 1 row . thinking loop lenght string . wrong becuse don`t know how string must get. remember 1 "quete" start "001" , end "1". try node

htmlnode node in doc.documentnode.selectnodes("//body/pre/br") 

but don`t work.

you need select p tags... i'd expect selectnodes("//p") or selectnodes("//body/p") instead of selecting single body element (which inner text contain concatenation of strings inside p tags).


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -