code_junkie

How to return an nvarchar(max) in a CLR UDF?

Nov 12th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. /// <summary>
  2. /// Replaces each occurrence of sPattern in sInput with sReplace. This is done with the
  3. /// CLR: new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace). The result of the replacement is
  4. /// the return value.
  5. /// </summary>
  6. [SqlFunction(IsDeterministic = true)]
  7. public static SqlString FRegexReplace(string sInput, string sPattern, string sReplace)
  8. {
  9. return new Regex(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace);
  10. }
  11.  
  12. /// <summary>
  13. /// Replaces each occurrence of sPattern in sInput with sReplace. This is done with the
  14. /// CLR: new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace). The result of the replacement is
  15. /// the return value.
  16. /// </summary>
  17. [SqlFunction(IsDeterministic = true)]
  18. [return: SqlFacet(MaxSize = -1)]
  19. public static SqlString FRegexReplace([SqlFacet(MaxSize = -1)]string sInput, string sPattern, string sReplace)
  20. {
  21. return new Regex(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace);
  22. }
Add Comment
Please, Sign In to add comment