mercredi 25 février 2015

Lose data when converting SqlChars to string?

I apologize if this has been asked, I cannot find a question that asks the same.


Is there a data loss when converting from SqlChars to string?


I need to use Regex in a SQL CLR user defined function to replace a pattern within the SqlChars value, but Regex is requiring a string input and its output is also a string.


Here is a sample code:



public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
[return: SqlFacet(MaxSize = -1)]
public static SqlChars RegexReplace(SqlChars text1, SqlString pattern, SqlString replacement)
{
return new SqlChars(Regex.Replace(text1.Value.ToString(), @pattern.Value, replacement.Value));
}
}


Thanks, Niki


Aucun commentaire:

Enregistrer un commentaire