C# 字符串函数到 T-SQL 标量函数
我想使用 ac# 函数来修改 html 有效 url 名称的字符串。该函数如下:
public static string HTMLValidName(string input)
{
string[] pattern = new string[] { "[^a-zA-Z0-9-]", "-+" };
string[] replacements = new string[] { "-", "-" };
input = input.Trim();
input = input.Replace("Ç", "C");
input = input.Replace("ç", "c");
input = input.Replace("Ğ", "G");
input = input.Replace("ğ", "g");
input = input.Replace("Ü", "U");
input = input.Replace("ü", "u");
input = input.Replace("Ş", "S");
input = input.Replace("ş", "s");
input = input.Replace("İ", "I");
input = input.Replace("ı", "i");
input = input.Replace("Ö", "O");
input = input.Replace("ö", "o");
for (int i = 0; i <= pattern.Length - 1; i++)
input = Regex.Replace(input, pattern[i], replacements[i]);
while(input.Contains("--"))
{
input = input.Replace("--", "-");
}
if (input[0] == '-') input = input.Substring(1, input.Length - 1);
return input;
}
我需要使用此函数来获取 SQL 结果。就像 SELECT ID FROM Categories WHERE HTMLValidName(Title)=@URLTitle
如何将其转换为 T-SQL 函数或者可以在 c# 中创建此函数?
I want to use a c# function which modifies a string for html valid url name. The function is like below:
public static string HTMLValidName(string input)
{
string[] pattern = new string[] { "[^a-zA-Z0-9-]", "-+" };
string[] replacements = new string[] { "-", "-" };
input = input.Trim();
input = input.Replace("Ç", "C");
input = input.Replace("ç", "c");
input = input.Replace("Ğ", "G");
input = input.Replace("ğ", "g");
input = input.Replace("Ü", "U");
input = input.Replace("ü", "u");
input = input.Replace("Ş", "S");
input = input.Replace("ş", "s");
input = input.Replace("İ", "I");
input = input.Replace("ı", "i");
input = input.Replace("Ö", "O");
input = input.Replace("ö", "o");
for (int i = 0; i <= pattern.Length - 1; i++)
input = Regex.Replace(input, pattern[i], replacements[i]);
while(input.Contains("--"))
{
input = input.Replace("--", "-");
}
if (input[0] == '-') input = input.Substring(1, input.Length - 1);
return input;
}
I need to use this function for SQL results. Like SELECT ID FROM Categories WHERE HTMLValidName(Title)=@URLTitle
How can I convert this to a T-SQL function or can I create this function in c#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建在 SQL Server 中运行的托管用户定义函数,从外部看就像普通的用户定义函数。有关详细信息,请参阅此处。
You can create a managed user defined function that runs in your SQL server and looks from the outside like a normal user defined function. See here for more info.