using System.Collections.Generic;
public static string GetName(string line)
List<string> names = new List<string>( new string[] {"Bobby", "Rod", "Stewart", "Andrew", "Lucy"} );
List<string> phrases = new List<string>( new string[] {"I'm", "My name is", "im", "I am"} );
foreach (string phrase in phrases) {
pos = line.IndexOf(phrase, StringComparison.CurrentCultureIgnoreCase);
string[] words = line.Substring(pos).Trim().Split(new char[] { ' ', ',', '.' });
foreach (string word in words) {
if (!names.Contains(word, StringComparer.OrdinalIgnoreCase))
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)));