using System.Collections.Generic;
public static void Main()
var suffices = GetSuffices();
var lou = new Suffixcles(suffices);
Yo("Marco M.D. Jr.", lou);
Yo("Marco, M.D., Sr.", lou);
Yo("Marco, M.D., Dr.", lou);
Console.WriteLine("Hello World");
private static List<IdName> GetSuffices()
private static void Yo(string name, Suffixcles lou)
var tuple = lou.Lou(name);
var stripName = tuple.Item1;
var suffix = tuple.Item2;
"[{0}] -> [{1}] ({2}:{3})",
(suffix == null ? null : (int?)suffix.Id),
(suffix == null ? null : suffix.Name));
private Dictionary<string, IdName> Dict {get; set; }
public Suffixcles(List<IdName> suffices = null)
Dict = CreateDictionary(suffices);
private Dictionary<string, IdName> CreateDictionary(List<IdName> suffices)
var dict = suffices.ToDictionary(s => s.Name, s => s);
foreach (var sfx in suffices.Where(s => s.Name.EndsWith(".")))
dict.Add(sfx.Name.Substring(0, sfx.Name.Length - 1), sfx);
public Tuple<string, IdName> Lou(string name)
Func<string, string, string> sfx = (d,v) =>
string.Format("{0}{1}", d, v);
var key = Dict.Keys.FirstOrDefault(k =>
name.EndsWith(sfx(" ", k))
|| name.EndsWith(sfx(",", k)));
return new Tuple<string, IdName>(name.Trim(), null);
var stripName = name.Substring(0, name.Length - key.Length - 1).Trim();
if (stripName.EndsWith(","))
stripName = stripName.Substring(0, stripName.Length - 1).Trim();
return new Tuple<string, IdName>(stripName, Dict[key]);
public int Id { get; set; }
public string Name { get; set; }
public static IdName Make(int id, string name)
return new IdName { Id = id, Name = name };