I am new to asp.net can you help me to find out how to find and extract the numbers from string in Asp.net.
Asked
Active
Viewed 1,206 times
2 Answers
0
string output = new string(input.Where(char.IsDigit).ToArray());

Damith
- 62,401
- 13
- 102
- 153
-
-
1
-
-
3A regex isn't free either. You won't notice a thing for both methods, you're too focused on premature optimization. – Jeroen Vannevel Dec 09 '13 at 04:54
0
Method 1:
String str = "udsdf34dfd78"; /*any string*/
String strNumber = "";
Regex regex=new Regex(@"\d");
foreach (Match m in regex.Matches(str))
strNumber += m.Value;
Method 2:
String str = "udsdf34dfd78"; /*any string*/
String strNumber = "";
foreach (Char c in str)
if (Char.IsDigit(c))
strNumber += c.ToString();

Sudhakar Tillapudi
- 25,935
- 5
- 37
- 67