Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用正则表达式删除aspx页面源代码中的CSS类?_C#_Css_Regex_Visual Studio 2010 - Fatal编程技术网

C# 如何使用正则表达式删除aspx页面源代码中的CSS类?

C# 如何使用正则表达式删除aspx页面源代码中的CSS类?,c#,css,regex,visual-studio-2010,C#,Css,Regex,Visual Studio 2010,我尝试重新排列我的sorce文件,例如:从aspx页面删除所有css样式。 我有一个文件(C:/file:mypage.aspx和30-40个aspx页面)如何在C#中使用正则表达式删除Css样式链接等?请我需要你最好的帮助这很重要:)我试图写一个winforms(.EXE)到罗马css属性 我想把下面的一切都移除 <link href="../Styles/Interm.css" rel="stylesheet" type="text/css" /> <styl

我尝试重新排列我的sorce文件,例如:从aspx页面删除所有css样式。 我有一个文件(C:/file:mypage.aspx和30-40个aspx页面)如何在C#中使用正则表达式删除Css样式链接等?请我需要你最好的帮助这很重要:)我试图写一个winforms(.EXE)到罗马css属性

我想把下面的一切都移除


   <link href="../Styles/Interm.css" rel="stylesheet" type="text/css" />
<style type="text/css">

// ERASE EVERYTHING
  </style>
  class="PageHeader"
CssClass="style1"

 CssClass="MyCss",CssFilePath="/test/style.css",CssPostFix="Aqua"

//抹去一切
class=“PageHeader”
CssClass=“style1”
CssClass=“MyCss”,CssFilePath=“/test/style.css”,CssPostFix=“Aqua”
我的代码:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace RemoverTags
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           richTextBox1.Text = RemoveWhiteSpaceFromStylesheets(richTextBox1.Text);
        }

        public  string RemoveWhiteSpaceFromStylesheets(string body)
        {
            body = Regex.Replace(body, "type="+"\"text/css\"", "");

            body = Regex.Replace(body, @"[a-zA-Z]+#", "#");

            body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty);

            body = Regex.Replace(body, @"\s+", " ");

            body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$1");

            body = body.Replace(";}", "}");

            body = Regex.Replace(body, @"([\s:]0)(px|pt|%|em)", "$1");



            // Remove comments from CSS

            body = Regex.Replace(body, @"/\*[\d\D]*?\*/", string.Empty);


            Regex r1 = new Regex(@"<style >([A-Za-z0-9\-]+)</style>");
            Match match = r1.Match(body);
            string v = "";
              if (match.Success)
              {
                   v = match.Groups[1].Value;

              }
              body = Regex.Replace(body, v, string.Empty);
              body = Regex.Replace(body, @"<(style|\n)*?>", string.Empty);
              body = Regex.Replace(body, @"<(/style|\n)*?>", string.Empty);
            return body;

        }

    }
}

but not working...

使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用System.Text.RegularExpressions;
命名空间删除标记
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
richTextBox1.Text=从样式表中删除空格(richTextBox1.Text);
}
公共字符串从样式表(字符串体)中删除空格
{
body=Regex.Replace(body,“type=“+”\“text/css\”,”);
body=Regex.Replace(body,@“[a-zA-Z]+#“,“#”);
body=Regex.Replace(body,@“[\n\r]+\s*”,string.Empty);
body=Regex.Replace(body,@“\s+”,“”);
body=Regex.Replace(body,@“\s”([:,;{}])\s?”,“$1”);
body=body.Replace(“;}”和“}”);
body=Regex.Replace(body,@“([\s:]0)(px | pt |%| em)”,“$1”);
//从CSS中删除注释
body=Regex.Replace(body,@/\*[\d\d]*?\*/”,string.Empty);
正则表达式r1=新正则表达式(@“([A-Za-z0-9\-]+)”;
匹配=r1。匹配(主体);
字符串v=“”;
如果(匹配成功)
{
v=匹配。组[1]。值;
}
body=Regex.Replace(body,v,string.Empty);
body=Regex.Replace(body,@“”,string.Empty);
body=Regex.Replace(body,@“”,string.Empty);
返回体;
}
}
}
但是不工作。。。

使用Visual Studio查找工具(ctrl+shift+f),转到“查找选项”并选择正则表达式来替换所有样式元素。

我认为您想从页面中自动删除CSS是正确的吗?我尝试将winforms(.EXE)编写到rome CSS属性。使用现有的工具,这会容易得多,而不是编写自己的程序。我能做到。您基本上是在告诉它“当您看到
时,开始删除行,直到您看到