Find and extract a number from a string

前端 未结 29 3180
温柔的废话
温柔的废话 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 03:45

      string verificationCode ="dmdsnjds5344gfgk65585";
                string code = "";
                Regex r1 = new Regex("\\d+");
              Match m1 = r1.Match(verificationCode);
               while (m1.Success)
                {
                    code += m1.Value;
                    m1 = m1.NextMatch();
                }
    

提交回复
热议问题