title: Get the first numbers from a string
body: <p>I want to get the first instance of numbers in a string.</p>
  
  <p>So I got this input string which could be one of the following:</p>
  
  <pre><code>1: "Event: 1 - Some event"
  2: "Event 12 -"
  3: "Event: 123"
  4: "Event: 12 - Some event 3"
  </code></pre>
  
  <p>The output of the input string must be:</p>
  
  <pre><code>1: 1
  2: 12
  3: 123
  4: 12
  </code></pre>
  
  <p>I've tried the following methods but none of them gives me exactly what I want.</p>
  
  <pre><code>number = new String(input.ToCharArray().Where(c =&gt; Char.IsDigit(c)).ToArray());
  //This gives me all the numbers in the string
  
  var index = input.IndexOfAny("0123456789".ToCharArray());
  string substring = input.Substring(index, 4);
  number = new string(substring.TakeWhile(char.IsDigit).ToArray());
  //This gives me first number and then the numbers in the next 4 characters. However it breaks if there is less than 4 characters after the first number.
  </code></pre>
  
  <p>EDIT: A lot of people posted good solutions but I ended up accepting the one I actually used in my code. I wish I could accept more answers!</p>