Search


Wednesday, March 11, 2009

How to remove char and leave number in c#

Regex.Replace Method

Within a specified input string, replaces strings that match a regular expression pattern with a specified replacement string.

ex.
// assigning value into the string xvalue.
string xvalue = "199 RemoveText";

// removing character and leave numbers
decimal value = (decimal)Regex.Replace(xvalue, @"[\D]", "");

//As the result:
199

No comments:

Post a Comment