Find and extract a number from a string

前端 未结 29 3194
温柔的废话
温柔的废话 2020-11-22 03:19

I have a requirement to find and extract a number contained within a string.

For example, from these strings:

string test = \"1 test\"
string test1 =         


        
29条回答
  •  独厮守ぢ
    2020-11-22 04:02

    You can do this using String property like below:

     return new String(input.Where(Char.IsDigit).ToArray()); 
    

    which gives only number from string.

提交回复
热议问题