Programming By A Tool Your one stop shop for one stop shops.



17Jul/080

Convert a String to a Number String With Linq… YAY

- Sean

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;
}
Related Posts
Tagged as: , , Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

NetDevInc.com