Thursday, July 17, 2008

Quick Linq thing... String to Number String

Really stupid little thing I came up with today... but I wanted to use Linq to strip any non number from a string and return the string with only numbers. I told you this was a stupid little thing.
public static String CreateNumberOnlyString(String textToCheck)
{
  String returnText;
               
  var queryForIntegers = from currentChar in textToCheck
                         where Char.IsNumber(currentChar)
                         select currentChar;
               
  returnText = new String(queryForIntegers.ToArray());
               
  return returnText;
}

No comments: