我有以下 SQL CLR C# UDF:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.Text;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString clrFn_GetDigits(string theWord)
{
if (theWord == null) { theWord = ""; }
string newWord = "";
char[] KeepArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\\', '/', '-', ' '};
foreach (char thischar in theWord)
{
foreach (char keepchar in KeepArray)
{
if (keepchar == thischar)
{
newWord += thischar;
}
}
}
return (SqlString)(newWord.Trim());
}
}
到目前为止,这很好用,除了以下地址:
141A, Some Street Avenue
4b, St Georges Street
16E Test Avenue
我希望我的函数返回 141A、4b 和 16E
有任何想法吗?