January 24, 2014 at 8:09 am
For lengthy strings, using CLR functions are the way to go. Not only are they much, much faster, they are very versatile. Attached is C# code for counting all non-letters and non-digits, which appears to be pretty close to what you need. You could also use other C# options in the same way--IsPunctuation, IsWhiteSpace, IsSymbol, IsLetter and IsDigit. Once you get started using CLR functions for strings, you'll be hooked.
using System;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Linq;
public class Not_LetterOrDigit
{
[SqlFunction()]
public static SqlString NotLetterOrDigit(string ColumnText)
{
int count = 0;
foreach (char c in ColumnText)
{
if (!char.IsLetterOrDigit(c))
{
count++;
}
}
return Convert.ToString(count);
}
}
Viewing post 31 (of 31 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy