Wednesday, April 10, 2013

How to get numbes form a string

Suppose you have a string which contains the number and chars and in functionality you only need numeric values.
Than just replace characters with blank values after it you will have numbers only.
we can use RegEx in code.

s = "adsf242343";

int numbersOnly = 0;

Int32.TryParse(System.Text.RegularExpressions.Regex.Replace(s, "[^0-9]+", string.Empty),

out numbersOnly);


No comments: