return only Digits 0-9 from a String

后端 未结 8 1963
遇见更好的自我
遇见更好的自我 2020-11-27 04:53

I need a regular expression that I can use in VBScript and .NET that will return only the numbers that are found in a string.

For Example any of the following \"str

8条回答
  •  不知归路
    2020-11-27 05:04

    The simplest solution, without a regular expression:

    public string DigitsOnly(string s)
       {
         string res = "";
         for (int i = 0; i < s.Length; i++)
         {
           if (Char.IsDigit(s[i]))
            res += s[i];
         }
         return res;
       }
    

提交回复
热议问题