I am looking for how to get rid of an exception. "The index was outside the array." for case 2 below
Purpose: to separate the first and last name (last name can be several times)
Case 1:
Name: John Melvick
I can resolve the first case with my code
Case 2:
Name: Kennedy
In case of two, I get an error. The index was out of range of LastName in my code
Case 3:
Name: Rudolph Nick Bother
In case 3, I can get:
FirstName: Rudolph and LastName: Nick (while I need Nick Bour to be last together)
Very grateful if anyone would help me.
Here is the code:
Match Names = Regex.Match(item[2], @"(((?<=Name:(\s)))(.{0,60})|((?<=Name:))(.{0,60}))", RegexOptions.IgnoreCase);
if (Names.Success)
{
FirstName = Names.ToString().Trim().Split(' ')[0];
LastName = Names.ToString().Trim().Split(' ')[1];
}
source
share