منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
حذف العناوين من الروابط - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة السي شارب C#.NET (http://vb4arb.com/vb/forumdisplay.php?fid=175)
+--- قسم : قسم اسئلة C#.NET (http://vb4arb.com/vb/forumdisplay.php?fid=176)
+--- الموضوع : حذف العناوين من الروابط (/showthread.php?tid=29943)

الصفحات: 1 2


RE: حذف العناوين من الروابط - elgokr - 21-06-19

السلام عليكم ورحمة الله وبركاته

تحويل كود الاخ سعود من VB.Net الى C#
كود :
           using (System.Net.WebClient wc = new System.Net.WebClient())
           {
               var u = "bidaya.html";
               wc.Encoding = Encoding.UTF8;
               string html = wc.DownloadString(u);
               html = System.Net.WebUtility.HtmlDecode(html);
               // <li><a id="bi" href="http://vb4arb.com/vb/forumdisplay.php?kanal=fid=2">a</a></li>
               var str = "<a.*?>.*?(.*?)</a>";
               System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(str, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
               System.Text.RegularExpressions.MatchCollection mc = reg.Matches(html);
               foreach (System.Text.RegularExpressions.Match h in mc)
               {
                   if (h.Success)
                   {
                       // txt(h.Value)
                       // txt(vbNewLine)
                       var txt = h.Groups[1].Value;
                       html = html.Replace(h.Groups[1].Value, string.Empty);
                   }
               }
           }

ولكن بالكود بالاعلى قمت باضافة كل مكتة تطلب الاستدعاء بكل سطر
فبدلاً من استخدام الكود بهذا الشكل كما بالاعلى 

عليك استخدامه بهذا الشكل
كود :
           using (WebClient wc = new WebClient())
           {
               var u = "bidaya.html";
               wc.Encoding = Encoding.UTF8;
               string html = wc.DownloadString(u);
               html = WebUtility.HtmlDecode(html);
               // <li><a id="bi" href="http://vb4arb.com/vb/forumdisplay.php?kanal=fid=2">a</a></li>
               var str = "<a.*?>.*?(.*?)</a>";
               Regex reg = new Regex(str, RegexOptions.IgnoreCase);
               MatchCollection mc = reg.Matches(html);
               foreach (Match h in mc)
               {
                   if (h.Success)
                   {
                       var txt = h.Groups[1].Value;
                       html = html.Replace(h.Groups[1].Value, string.Empty);
                   }
               }
           }

بعد اتمام الامر قم عمل استدعاء للتالي
كود :
using System.Net;
using System.Text.RegularExpressions;

تحياتى لك
وتمنياتى لك التوفيق



RE: حذف العناوين من الروابط - bidaya - 21-06-19

(21-06-19, 06:02 PM)elgokr كتب :
السلام عليكم ورحمة الله وبركاته

تحويل كود الاخ سعود من VB.Net الى C#
كود :
           using (System.Net.WebClient wc = new System.Net.WebClient())
           {
               var u = "bidaya.html";
               wc.Encoding = Encoding.UTF8;
               string html = wc.DownloadString(u);
               html = System.Net.WebUtility.HtmlDecode(html);
               // <li><a id="bi" href="http://vb4arb.com/vb/forumdisplay.php?kanal=fid=2">a</a></li>
               var str = "<a.*?>.*?(.*?)</a>";
               System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(str, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
               System.Text.RegularExpressions.MatchCollection mc = reg.Matches(html);
               foreach (System.Text.RegularExpressions.Match h in mc)
               {
                   if (h.Success)
                   {
                       // txt(h.Value)
                       // txt(vbNewLine)
                       var txt = h.Groups[1].Value;
                       html = html.Replace(h.Groups[1].Value, string.Empty);
                   }
               }
           }

ولكن بالكود بالاعلى قمت باضافة كل مكتة تطلب الاستدعاء بكل سطر
فبدلاً من استخدام الكود بهذا الشكل كما بالاعلى 

عليك استخدامه بهذا الشكل
كود :
           using (WebClient wc = new WebClient())
           {
               var u = "bidaya.html";
               wc.Encoding = Encoding.UTF8;
               string html = wc.DownloadString(u);
               html = WebUtility.HtmlDecode(html);
               // <li><a id="bi" href="http://vb4arb.com/vb/forumdisplay.php?kanal=fid=2">a</a></li>
               var str = "<a.*?>.*?(.*?)</a>";
               Regex reg = new Regex(str, RegexOptions.IgnoreCase);
               MatchCollection mc = reg.Matches(html);
               foreach (Match h in mc)
               {
                   if (h.Success)
                   {
                       var txt = h.Groups[1].Value;
                       html = html.Replace(h.Groups[1].Value, string.Empty);
                   }
               }
           }

بعد اتمام الامر قم عمل استدعاء للتالي
كود :
using System.Net;
using System.Text.RegularExpressions;

تحياتى لك
وتمنياتى لك التوفيق
بارك الله لك وفيك
الله ارزقك الصحة والعافية
شكرا لك اخي الكريم على ما تقدمه للمنتدى

                                             



RE: حذف العناوين من الروابط - elgokr - 21-06-19

الشكر لله والحمد لله

والحمد لله على كل حال

تحياتى لك
وتمنياتى لك التوفيق