title: How to separate a first name and last name in c#?
body: <p>I am looking for how to get rid off below exception "Index was outside the bounds of the array." for the below case 2</p>
  
  <p>Aim: To separate the first name and last name (last name may be null some times)</p>
  
  <p><strong>Case 1:</strong></p>
  
  <p>Name: John Melwick</p>
  
  <p>I can be able to resolve the first case with my code</p>
  
  <p><strong>Case 2:</strong></p>
  
  <p>Name: Kennedy </p>
  
  <p>In case two I am getting an error Index was out of range at <strong>LastName</strong> in my code</p>
  
  <p><strong>Case 3:</strong></p>
  
  <p>Name: Rudolph Nick Bother</p>
  
  <p>In case 3, I can be able to get:</p>
  
  <p>FirstName: Rudolph and LastName: Nick (whereas I need Nick Bother together to be lastname)</p>
  
  <p>Very much thankful, if anybody help me.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>Match Names = Regex.Match(item[2], @"(((?&lt;=Name:(\s)))(.{0,60})|((?&lt;=Name:))(.{0,60}))", RegexOptions.IgnoreCase);
  
  if (Names.Success)
  {
      FirstName = Names.ToString().Trim().Split(' ')[0];                      
      LastName = Names.ToString().Trim().Split(' ')[1];
  }
  </code></pre>