Parse integer from string containing letters and spaces - C#
问题 What is the most efficient way to parse an integer out of a string that contains letters and spaces? Example: I am passed the following string: "RC 272". I want to retrieve 272 from the string. I am using C# and .NET 2.0 framework. 回答1: Since the format of the string will not change KISS: string input = "RC 272"; int result = int.Parse(input.Substring(input.IndexOf(" "))); 回答2: A simple regex can extract the number, and then you can parse it: int.Parse(Regex.Match(yourString, @"\d+").Value,