当前位置: 首页>>代码示例>>C#>>正文


C# Regex.Remove方法代码示例

本文整理汇总了C#中System.Text.RegularExpressions.Regex.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.Remove方法的具体用法?C# Regex.Remove怎么用?C# Regex.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.RegularExpressions.Regex的用法示例。


在下文中一共展示了Regex.Remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetHtml

        public static string GetHtml(Parser parser)
        {
            string document = parser.GetDocument();

            StringBuilder html = new StringBuilder();

            html.Append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n");
            html.Append("<html>\r\n<head>\r\n<title>Title</title>\r\n<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\">\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>\r\n");

            if (!parser.GetSuccess())
            {
                html.Append("<p>Errors occurred while parsing the document. Please correct these before trying to export.</p>\r\n");
            }
            else
            {
                // Convert @pageref links to actual page numbers
                document = new Regex("@pageref\\((.+?)\\)").Replace(document, "<a href='#$1' class='pageref'>this link</a>");

                // Center lines
                document = new Regex("^--\\s*(.*?)\\s*$", RegexOptions.Multiline).Replace(document, "<p style='text-align: center'>$1</p>");

                // Convert lines to paragraphs (ignoring any figures, tables, or raw html)
                MatchCollection paragraphs = new Regex("(^([^@figure\\(|^@table\\(|^\n|^#|^\\$|^\\<].+?)\n)+", RegexOptions.Multiline).Matches(document);

                for (int i = paragraphs.Count - 1; i >= 0; i--)
                {
                    Match m = paragraphs[i];

                    document = document.Remove(m.Index, m.Length);
                    document = document.Insert(m.Index, "<p>\n" + m.Groups[0].Value.ToString().Substring(0, m.Groups[0].Value.Length - 1).Replace("\n", "<br>\n") + "\n</p>\n");
                }

                // Convert lines only containing # to vertical padding paragraphs
                document = new Regex("^#\n", RegexOptions.Multiline).Replace(document, "<p><br></p>\n");

                document = ProcessChapters(document, parser.GetChapters());
                document = ProcessFigures(document, parser.GetFigures());
                document = ProcessTables(document, parser.GetTables());
                document = ProcessReferences(document, parser.GetReferences());

                html.Append(document);
            }

            html.Append("</body></html>");

            return html.ToString();
        }
开发者ID:DesktopMan,项目名称:Report-Writer,代码行数:47,代码来源:HtmlGenerator.cs

示例2: GetDescription

        private static string GetDescription(string temp)
        {
            const string startMainDescrRegex = "\\<td .* class=\"mainDescription\"\\>";
            const string allCharacteresRegex = "((.*(\n)*)*)";
            const string endMainDescrRegex = "\\</td\\>";

            //wycina tymczasowo cały od rozpoczęcia regexu
            var productMainDescrTemp = new Regex(startMainDescrRegex + allCharacteresRegex).Match(temp).Value;

            //wstępne porządki
            const string checkRegex = "table";
            var checkRegexTemp = new Regex(checkRegex).Match(productMainDescrTemp);
            if (checkRegexTemp.Success)
            {
                const string cleanRegex = "\\<table.*\r\n\\s*.*\r\n\\s*.*\r\n\\s*.*\\</table\\>\\<br\\>";
                productMainDescrTemp = new Regex(cleanRegex).Replace(productMainDescrTemp, "");
            }

            //zwraca ile znaków zajmuje startMainDescrRegex
            //+ 2 - usunięcie \r\n z początku napisu
            var productMainDescrStartLocation = new Regex(startMainDescrRegex).Match(productMainDescrTemp).Length + 2;

            //zwraca początek </td>
            //- productmainDescrEndLocation - w substring podaje się ile znaków ma się wyciąć, a nie - końcowy indeks
            var productMainDescrEndLocation = new Regex(endMainDescrRegex).Match(productMainDescrTemp).Index - productMainDescrStartLocation;

            productMainDescrTemp = productMainDescrTemp.Substring(productMainDescrStartLocation, productMainDescrEndLocation);

            //porządki
            const string clearingChars = "'";
            productMainDescrTemp = new Regex(clearingChars).Replace(productMainDescrTemp, "");

            //porządki 2
            const string clearRegex = "\\<br\\>\\<br\\>\\<br\\>";
            var clearRegexTemp = new Regex(clearRegex).Match(productMainDescrTemp).Index;

            if (clearRegexTemp != 0)
                productMainDescrTemp = productMainDescrTemp.Remove(clearRegexTemp);

            //porządki 3
            const string clearRegex2 = "\\<br\\>\\<br\\>\r\n\\s+\\<font";
            var clearRegex2Temp = new Regex(clearRegex2).Match(productMainDescrTemp).Index;

            if (clearRegex2Temp != 0)
                productMainDescrTemp = productMainDescrTemp.Remove(clearRegex2Temp);

            //porządki 4
            const string clearRegex3 = "\\<br\\>\r\n\\s*\\<br\\>\\<img src=\"http://www.*";
            productMainDescrTemp = new Regex(clearRegex3).Replace(productMainDescrTemp, "");

            //porządki 5
            const string clearRegex4 = "\\<br\\>.*[email protected]\\.pl.*\r\n\\s*.*";
            productMainDescrTemp = new Regex(clearRegex4).Replace(productMainDescrTemp, "");

            //porządki 6
            const string clearRegex5 = "\\<br\\>\r\n\\s*" + clearRegex4;
            productMainDescrTemp = new Regex(clearRegex5).Replace(productMainDescrTemp, "");

            return productMainDescrTemp;
        }
开发者ID:dev4s,项目名称:2010-moto-akcesoria-web-crawler,代码行数:60,代码来源:Program.cs

示例3: WeatherYandexRu

 private void WeatherYandexRu()
 {
     try
     {
         var city = string.Empty;
         var sr = new StreamReader(LoadSetting);
         Line = sr.ReadLine();
         sr.Close();
         var users = new Users();
         var list = users.Read(UsersPath);
         if (Line != "Гостем")
         {
             foreach (var t in list.Where(t => t.Login == Line))
             {
                 textBoxInput.Text = @"Вы зашли под," + t.Login;
                 city = t.City;
                 User = t.Login;
                 break;
             }
         }
         else
         {
             textBoxInput.Text = @"Вы зашли под," + Line;
             User = Line;
             ExitFromAccount.Visible = false;
             textBoxCityVariable.Text = @"Grodno";
         }
         var request = WebRequest.Create(@"https://pogoda.yandex.ru/" + city);
         using (var response = request.GetResponse())
         {
             using (var stream = response.GetResponseStream())
                 if (stream != null)
                     using (var reader = new StreamReader(stream))
                     {
                         var data = reader.ReadToEnd();
                         var temp =
                             new Regex(
                                 @"<div class=""current-weather__thermometer current-weather__thermometer_type_now"">(?<temp>([+][0-9]{1,2})|(-[0-9]{1,2})|[0]+)")
                                 .Match(data).Groups["temp"].Value;
                         textBoxWeather.Text = temp + @" °C";
                         var temp1 =
                             new Regex(
                                 @"<span class=""current-weather__comment"">(?<temp1>([а-я]+\s[а-я]+)|([а-я]+,\s[а-я]+)|([а-я]+))")
                                 .Match(data).Groups["temp1"].Value;
                         textBoxWeaher1.Text = temp1.Substring(0, 1).ToUpper() + temp1.Remove(0, 1);
                         if (city != string.Empty)
                         {
                             textBoxCityVariable.Text = city.Substring(0, 1).ToUpper() + city.Remove(0, 1);
                         }
                         else
                         {
                             city = @"Grodno";
                             textBoxCityVariable.Text = city.Substring(0, 1).ToUpper() + city.Remove(0, 1);
                         }
                     }
         }
         Log.Info("WeatherConnect");
     }
     catch (Exception exception)
     {
         Log.Fatal(exception.Message);
         MessageBox.Show(exception.Message);
     }
 }
开发者ID:Neverkevich-Maxim,项目名称:WebBrowser,代码行数:64,代码来源:Main.cs


注:本文中的System.Text.RegularExpressions.Regex.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。