.net - regex split implementation for sql server -
I created a function to implement regex.split in scll. Here's the code:
Private static IEnumerable & lt; Indexed value & lt; T & gt; & Gt; ToIndexedValue & lt; T & gt; (IEnumerable & lt; T & gt; List) {int idx = 1; Foreign exchange (T-value in the list) yield returns new indexed value & lt; T & gt; (++ idx, value); } Private Start Indexed Value & lt; T & gt; {Public INS index; Public t value; Public index value (int index, t value) {index = index; Value = value; }} Fixed static IEnumerable RegexSplit (SqlString Input, SqlString Pattern) {If (input.IsNull) input = string [SqlFunction (FillRowMethodName = "FillSplit", TableDefinition = "[ID] int, [value] nvarchar (max)")] .Empty; If (pattern.IsNull) Pattern = String.Empty; Try {Return toIndexedValue & lt; String & gt; (Regex.Split (input.Value, pattern.Value, Options); } Hold {throw; }} Public static zero FillSplit (commodity obj, out id, outside SqlString value) {IndexedValue & lt; String & gt; Iv = (indexed value & lt; string & gt;) obj; Id = iv.index; Value = iv.Value; }
But when I try, I get ID values but get empty text values. Can someone help me?
Here you (compile as SQL CLR assembly):
< Using the Code> system. compilation; Using System.Text.RegularExpressions; Using Microsoft.SqlServer.Server; Public Partial Category UserDefinedFunctions {[SqlFunction] Public Stable Bull RegexMatch (string expr, string regex) {returning Regex.IsMatch (expr, regex); } [SqlFunction] Public static string RegexReplace (string expr, string regex, replace string) {return Regex.Replace (expr, regex, replace); } [SqlFunction (FillRowMethodName = "gettoken", Table Definition = "value nvarchar (max)")) Public static IEnumerable RegexSplit (string expr, string regex) {returning Regex.Split (expr, regex); } Public static zero GetToken (object line, string outside str) {str = (string) line; }}
Basically:
Comments
Post a Comment