Extract multiple integers from string and store as int

前端 未结 3 1205
無奈伤痛
無奈伤痛 2021-01-24 02:20

I know that this will extract the number and store as int -

string inputData = \"sometex10\";

string  data = System.Text.RegularExpressions.Regex.Match(inputDa         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-24 02:32

    You can use a LINQ one-liner:

    var numbers = Regex.Matches(inputData, @"\d+").Select(m => int.Parse(m.Value)).ToList();
    

    Or use ToArray() if you prefer an array instead of a list.

提交回复
热议问题