Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.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# 将正则表达式字符串传递给程序集_C#_Sql_Parameters_.net Assembly - Fatal编程技术网

C# 将正则表达式字符串传递给程序集

C# 将正则表达式字符串传递给程序集,c#,sql,parameters,.net-assembly,C#,Sql,Parameters,.net Assembly,我使用这个SQL程序集从字符串中删除一些html标记。对于固定的正则表达式字符串,它工作得非常好,但我希望在调用函数时必须将正则表达式字符串作为字符串参数 我曾尝试将正则表达式作为字符串传递到函数中,但它不起作用。我的猜测是,我必须以不同的格式通过它 这是类库 using System.Data.SqlTypes; using System.Text.RegularExpressions; using Microsoft.SqlServer.Server; public class Funct

我使用这个SQL程序集从字符串中删除一些html标记。对于固定的正则表达式字符串,它工作得非常好,但我希望在调用函数时必须将正则表达式字符串作为字符串参数

我曾尝试将正则表达式作为字符串传递到函数中,但它不起作用。我的猜测是,我必须以不同的格式通过它

这是类库

using System.Data.SqlTypes;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Server;

public class Functions
{
    [SqlFunction]
    public static SqlString RemoveHtmlTags(string inText)
    {

        // Remove html tags other than<p> <b> <h3> <i> <u> <ul> <ol> <li> <strong>
        return Regex.Replace(inText, "<\\s*?\\/?(?!(p|b|h3|i|u|ul|ol|li|strong))\\w*\\s*?>", "");
    }
}
我想要的是:

using System.Data.SqlTypes;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Server;

public class Functions
{
    [SqlFunction]
    public static SqlString RemoveHtmlTags(string inText, string regexText)
    {

       // Remove html tags other than<p> <b> <h3> <i> <u> <ul> <ol> <li> <strong>
        return Regex.Replace(inText, regexText, "");
    }

}
使用System.Data.SqlTypes;
使用System.Text.RegularExpressions;
使用Microsoft.SqlServer.Server;
公共类功能
{
[SqlFunction]
公共静态SqlString RemoveHtmlTags(string-inText,string-regextextext)
{
//删除html标记而不是
  • 返回Regex.Replace(inText,regexText,“”); } }
SQL Server 2012。当我将正则表达式作为字符串参数传递时,它没有像修复正则表达式时那样删除任何html标记。

您使用的是哪种dbms?“但它不会工作”不足以作为错误描述。请(通过编辑问题)添加它如何不起作用。你有错误吗?如果是,有哪些信息?您得到的结果是否与预期结果不同?如果是,请添加一个示例。我们不建议在html上使用正则表达式,因为正则表达式代表正则表达式,而html不是正则表达式。它可能在有限的应用中起作用,但不会在所有情况下都起作用。
using System.Data.SqlTypes;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Server;

public class Functions
{
    [SqlFunction]
    public static SqlString RemoveHtmlTags(string inText, string regexText)
    {

       // Remove html tags other than<p> <b> <h3> <i> <u> <ul> <ol> <li> <strong>
        return Regex.Replace(inText, regexText, "");
    }

}