2016-04-10 26 views
1

其實我想跨越我的textbox1.Text區域的數據值顯示。C#Windows應用程序 - 如何跨越標籤值顯示在文本框1?

這是完整的代碼。

<td id="yiv9101838563i4" style="padding:0;padding-top:25px;font-family:'Segoe UI', Tahoma, Verdana, Arial, sans-serif;font-size:14px;color:#2a2a2a;">Security code: <span style="font-family:'Segoe UI Bold', 'Segoe UI Semibold', 'Segoe UI', 'Helvetica Neue Medium', Arial, sans-serif;font-size:14px;font-weight:bold;color:#2a2a2a;">7201</span></td> 

這是接收的碼

<span style="font-family:'Segoe UI Bold', 'Segoe UI Semibold', 'Segoe UI', 'Helvetica Neue Medium', Arial, sans-serif;font-size:14px;font-weight:bold;color:#2a2a2a;">7201</span> 

我已經檢查了許多來源的解決方案,但我沒能找到一個解決辦法,所以我在等待的人好答覆。

我想知道如何跨越textbox1.Text區域中顯示的值。

我也試過下面的代碼,但是不起作用。

HtmlElementCollection bColl = webBrowser3.Document.GetElementsByTagName("span"); 
foreach (HtmlElement bEl in bColl) 
{ 
    if (bEl.GetAttribute("style").Contains("font-family:'Segoe UI Bold'")) 
     txtlink.Text = bEl.OuterHtml; 
} 
+0

什麼是期望的輸出? – Druzion

+0

7201這個數字我想在我的文本框中顯示,但不顯示任何輸出。 Mabe我在某個地方犯錯了。請幫助我。 – browsersumon

+0

因此,爲了確認,您希望RegEx在您的問題中從第一個HTML字符串中選擇「7201」? – Druzion

回答

-1

試試這個正則表達式:

<td\s.*?>.*?<span\s.*?>(.*?)<\/span><\/td> 

你想存儲在1st捕獲組

Live Demo on Regex101

它是如何工作的數據:

<td\s.*?>   # Opening <td> with attributes 
.*?    # Optional Data - i.e. Security Code: (Lazy) 
<span\s.*?>  # Opening <span> with attributes 
(.*?)    # The data you need to Capture - i.e. 7201 
<\/span>   # Closing </span> 
<\/td>    # Closing </td> 
+0

親愛的朋友,我不知道如何使用正則表達式,所以你可以給我完整的代碼,然後我要測試。請爲我做我正在等待您的更新。謝謝 – browsersumon

+0

@browsersumon StackOverflow不是免費的編碼服務。首先,嘗試[谷歌搜索](https://www.google.com/search?q=using+regex+in+c%23)。然後在C#中使用RegEx找到一些教程 – Druzion

+0

@browsersumon試試[本站](http://www.dotnetperls.com/regex)和[本站](http://regexone.com/references/csharp)。這就是我給你的所有信息。 – Druzion

相關問題