Get specific numbers from string
c#, split, string
Solution
This will create an array of integers from the string:
using System.Linq;
using System.Text.RegularExpressions;
class Program {
static void Main() {
string text = "12 text text 7 text";
int[] numbers = (from Match m in Regex.Matches(text, @"\d+") select int.Parse(m.Value)).ToArray();
}
}
Problem
In my current project I have to work alot with substring and I'm wondering if there is an easier way to get out numbers from a string. Example: I have a string like this: 12 text text 7 text I want to be available to get out first number set or second number set. So if I ask for number set 1 I will get 12 in return and if I ask for number set 2 I will get 7 in return. Thanks!