How to find the first number form a string (match one or more digits together) in C#

1 Answer

0 votes
using System;
using System.Text.RegularExpressions;

namespace ConsoleApplication_C_Sharp
{
    static class Program
    {
        static void Main()
        {
            string s = "C# 13 Java 89 Python";
            Match match = Regex.Match(s, "\\d+");

            if (match.Success)
                Console.WriteLine(match.Value);
        }
    }
}


/*
run:
  
13
   
*/

 



answered Oct 13, 2018 by avibootz
...