CSharp examples for System:String Number
Extract Number from String
// Copyright (c) 2012 Computer Technology Solutions, Inc. ALL RIGHTS RESERVED using System.Text.RegularExpressions; using System.Text; using System.Linq; using System.Globalization; using System.Collections.Generic; using System;/*from www . j ava2s . c o m*/ public class Main{ public static int ExtractNumber(this string str) { var chars = str.ToCharArray(); var nums = new List<char>(); foreach (var c in chars) if (char.IsNumber(c)) nums.Add(c); if (nums.Count > 0) return int.Parse(new string(nums.ToArray())); return 0; } }