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#_Asp.net Mvc_Tinymce - Fatal编程技术网

C# 如何获得<;李>;从数据库字段?

C# 如何获得<;李>;从数据库字段?,c#,asp.net-mvc,tinymce,C#,Asp.net Mvc,Tinymce,在我的应用程序中,我使用TINYMCE作为html编辑器来接受以下值: 速成课程 泽里克斯 最佳创新者 最佳来源 一旦插入,数据库中的字段看起来像这样 <ul> <li>Speedy Course</li> <li>Zerix</li> <li>Optimum Innovatus</li> <li>Optimum Source</li> </ul> 快车道 泽里克斯 最

在我的应用程序中,我使用TINYMCE作为html编辑器来接受以下值:
  • 速成课程
  • 泽里克斯
  • 最佳创新者
  • 最佳来源

一旦插入,数据库中的字段看起来像这样

<ul>
<li>Speedy Course</li>
<li>Zerix</li>
<li>Optimum Innovatus</li>
<li>Optimum Source</li>
</ul>
  • 快车道
  • 泽里克斯
  • 最佳创新者
  • 最佳来源
现在我想在访问数据时获取li标记的值

有没有一种快速、简便的方法?我能想到的唯一方法是通过逐个循环值。顺便说一下,我正在使用MVC3


非常感谢。

不确定您是否在使用SQL,但如果是这样,您可以将这两个CLR项添加到数据库中

[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, IsPrecise = true, Name = "RegExSplitIndex",
    SystemDataAccess = SystemDataAccessKind.None, FillRowMethodName = "RegExSplitIndexRow",
    TableDefinition =
        "Match NVARCHAR(MAX), MatchIndex INT, MatchLength INT, NextMatchIndex INT"
    )]
 public static IEnumerable RegExSplitIndex(SqlString input, SqlString pattern, SqlInt32 options)
{
    if (input.IsNull || pattern.IsNull) return null;
    var matchcol = Regex.Matches(input.Value, pattern.Value, (RegexOptions)options.Value);


    var matches = matchcol.Cast<Match>().ToList().Select(MatchKeys.Translate).ToList();

    if (matches.Any() && matches.All(i => i.MatchIndex != 0))
    {
        var ix = matches.OrderBy(i => i.MatchIndex).First().MatchIndex;
        matches.Add(new MatchKeys() {MatchIndex = 0, MatchLength = 0, NextMatchIndex = ix});

    }

    return matches;
}

public static void RegExSplitIndexRow(Object input, ref SqlString match, ref SqlInt32 matchIndex, ref SqlInt32 matchLength, ref SqlInt32 nextMatchIndex)
{
    MatchKeys m = (MatchKeys)input;
    match = new SqlString(m.Match);
    matchIndex = m.MatchIndex;
    matchLength = m.MatchLength;
    nextMatchIndex = m.NextMatchIndex;
} 
[SqlFunction(DataAccess=DataAccessKind.None,IsDeterministic=true,IsPrecise=true,Name=“RegExSplitIndex”,
SystemDataAccess=SystemDataAccessKind.None,FillRowMethodName=“RegExSplitIndexRow”,
表定义=
匹配NVARCHAR(MAX)、匹配索引INT、匹配长度INT、NextMatchIndex INT
)]
公共静态IEnumerable RegExSplitIndex(SqlString输入、SqlString模式、SqlInt32选项)
{
if(input.IsNull | | pattern.IsNull)返回null;
var matchcol=Regex.Matches(input.Value,pattern.Value,(RegexOptions)options.Value);
var matches=matchcol.Cast().ToList().Select(MatchKeys.Translate).ToList();
if(matches.Any()&&matches.All(i=>i.MatchIndex!=0))
{
var ix=matches.OrderBy(i=>i.MatchIndex.First().MatchIndex;
Add(new MatchKeys(){MatchIndex=0,MatchLength=0,nextMatchHindex=ix});
}
返回比赛;
}
公共静态void RegExSplitIndexRow(对象输入,ref SqlString匹配,ref SqlInt32 matchIndex,ref SqlInt32 matchLength,ref SqlInt32 nextmatchhindex)
{
匹配键m=(匹配键)输入;
match=新的SqlString(m.match);
matchIndex=m.matchIndex;
匹配长度=m.匹配长度;
nextMatchIndex=m.nextMatchIndex;
} 
然后在sql查询中,您可以使用如下拆分函数拆分html标记:

OUTER APPLY [dbo].RegExSplitIndex(<YourdbField>),'(<(?:"[^"]*"[''"]*|''[^'']*''[''"]*|[^''">])+>)|\n',0) REM
OUTER APPLY[dbo].RegExSplitIndex(),'(]+>)|\n',0)REM
并检查匹配值的大小(
[REM].[match]='
  • '
  • 您可以使用匹配索引和长度来知道从何处开始从拆分字符串获取实际值


    如果您没有CLR的访问权限,那么您仍然可以使用regex进行拆分,并使用类似的策略从代码中执行所有操作

    数据来自数据库,而不是网页。