public static void Main()
string[] lines = { "Hi, I'm Bobby", "My name is Rod Stewart", "Nice to meet you, im Andrew...",
"I am Lucy it's nice to meet you", "im stewart, how are you doing?", "There's no name here", "Hi I'm nobody",
"I am an idiot", "I'm Lucy Stewart and I like cars.", "Where is Lucy and her dog?", "I am hungry but I want to see Lucy first." };
foreach (string s in lines) {
Console.WriteLine(string.Format("{0} => {1}", s, GetName(s)));
public static string GetName(string str)
if(str.Contains("?") || str.Contains("but"))
string[] subs = str.Split(' ');
for(int i = 1; i < subs.Length; i++)
if(Char.IsUpper(subs[i][0]) && subs[i].Length > 1 && !subs[i].Contains("\'"))