SQL CLR C# User Defined Function - Get house or flat number from address -
SQL CLR C# User Defined Function - Get house or flat number from address -
i have next 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; } } } homecoming (sqlstring)(newword.trim()); } }
this works great far except addresses below:
141a, street avenue 4b, st georges street 16e test avenue
i want function homecoming 141a, 4b , 16e
any ideas?
i have not tested below code, along lines, error checking need in place ensure converts not fail solution gives need
char[] keeparray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\\', '/', '-', ' ' }; foreach (char thischar in theword) { if (keeparray.contains(thischar)) { newword += thischar; } else if (char.isletter(thischar) && newword.length > 0){ seek { if (char.isdigit((convert.tochar(newword.substring(newword.length - 1, 1))))) { newword += thischar; } } grab { } } }
c# sql clr user-defined-functions
Comments
Post a Comment