how to find ASCII characters in a table?

  • 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