How does C # detect what numbers are in a string string?

Source: Internet
Author: User
how does C # detect what numbers are in a string string?

  Test function        private void Form1_Load (object sender, EventArgs e)        {            foreach (var number in Extractnumbersfromstring ("abc2345 345fdf678 jdhfg945"))            {                MessageBox.Show (number. ToString ());            }        }        Private Ienumerable<int> extractnumbersfromstring (string s)        {            //regex.matches Method: Searches the input string for all occurrences of the regular expression and returns all matches.            matches the preceding character or sub-expression one or more times. Equivalent to {1,}. If the + is removed, it is            //return regex.matches (S, @ "\d+"). Cast<match> (). Select (M = Convert.ToInt32 (M.value));            Return Regex.Matches (S, @ "\d"). Cast<match> (). Select (M = Convert.ToInt32 (M.value));        }

"Abc2345 345fdf678 jdhfg945"
The above example test, there is a plus, this output:

2345  345678945

When there is no +, the output is this:

23453 .....

The above is how C # detects what numbers are in string strings? For more information, please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.