Windows应用程序中的代码拆分 [英] code split in windows application

查看:69
本文介绍了Windows应用程序中的代码拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,

我的问题是我需要从webbrowser中读取文本
然后,当我单击按钮时,在网络浏览器中拆分文本,然后将其放入
在文本框中拆分文本

Good day,

My problem is I need to read the text from webbrowser
then when I click on button split the text in web browse and put this
text split in textbox

推荐答案



如果您正在谈论提取Web浏览器控件中的内容,那么这里是代码,否则请解释一下.

在此示例中,我使用的是richtextbox.此示例在此处显示了通过所有html元素遍历或通过标签获取html元素的方法(甚至也可以通过ID获取该元素).然后获取每个元素的详细信息.这样,您可以将html逐元素拆分.如果要分割任何字符串,请使用分割功能

Hi,

If you are talking about extracting the content in the webbrowser control then here is the code, otherwise excuse and explain a bit more.

I am using a richtextbox in this example. This example here shows a walk thorugh all html elements or get a html element by tag (even can get the element by ID as well). Then get each element''s details. That way you can split the html into element by element. If you want split any string use the split function

private void button1_Click(object sender, EventArgs e)
{
   HtmlDocument doc=  (HtmlDocument)webBrowser1.Document;
   richTextBox1.AppendText("<html>");

    //Get elements by tag.
   HtmlElementCollection coll1= doc.GetElementsByTagName("head");

   //if want to walk through all elements then
   HtmlElementCollection coll2 = doc.All;
   foreach (HtmlElement element in coll1)
   {
       //Here can get elements properties like
       //(just for example i am declaring variables inside the loop, it is not good way)

       string name=element.Name;
       string id = element.Id;
       string innerHtml = element.InnerHtml;
       string outerHtml = element.OuterHtml;


       //Navigate around
       HtmlElement firstChild = element.FirstChild;
       HtmlElement nextSibling = element.NextSibling;
       HtmlElementCollection children = element.Children;



       richTextBox1.AppendText(element.OuterHtml);
   }
   richTextBox1.AppendText(doc.Body.OuterHtml);
   richTextBox1.AppendText("</html>");
}


第二部分请看MSDN上的String.Split().

我认为您可以做的第一部分,因为这是很常见的事情,因此您已经可以通过互联网搜索找到答案.
For the second part take a look at String.Split() on MSDN.

I assume that you can do the first part, since that is a very common thing to do and so you will already have found the answer with an internet search.


这篇关于Windows应用程序中的代码拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆