2006-05-05

Filter numbers out of a string

Here you find a method that filters the numbers out of a string:
public static string FilterNumbers(string mightContainNumbers)
{
    if (mightContainNumbers == null || mightContainNumbers.Length == 0) return "";

    StringBuilder builder = new StringBuilder(mightContainNumbers.Length);
    foreach (char c in mightContainNumbers)
        if (Char.IsNumber(c))
            builder.Append(c);

    return builder.ToString();
}
Tags: .
Comments: Post a Comment

Links to this post:

Create a Link