Using LINQ to parse the numbers from a string
问题 Is it possible to write a query where we get all those characters that could be parsed into int from any given string? For example we have a string like: "$%^DDFG 6 7 23 1" Result must be "67231" And even slight harder: Can we get only first three numbers? 回答1: This will give you your string string result = new String("y0urstr1ngW1thNumb3rs". Where(x => Char.IsDigit(x)).ToArray()); And for the first 3 chars use .Take(3) before ToArray() 回答2: The following should work. var myString = "$%^DDFG