Extract multiple integers from string and store as int

前端 未结 3 1207
無奈伤痛
無奈伤痛 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:48

    You can use something like this:

    string inputData = "sometex10";
    List numbers = new List();
    foreach(Match m in Regex.Matches(inputData, @"\d+"))
    {
        numbers.Add(Convert.ToInt32(m.Value));
    }
    

    This will store the integers in the list numbers

提交回复
热议问题