Reputation: 292
I'm making a random name generator. Problem is, I have many names, and I probably added them in a stupid way. I added the names to two lists like this...
listFO.Add("Sir");
listFO.Add("Lady");
listFO.Add("Captain");
listFO.Add("Mr");
listFO.Add("Ms");
and the other like this
listFN.Add("Gambler");
listFN.Add("Katja");
listFN.Add("John");
listFN.Add("Nillo");
just with many more names. Now other than the fact that I probably added these names in an inefficient way - what would be an efficient way of making a program that sees a name like 'CaptainNillo' and plays a sound called 'Captain.wav' first and then Nillo.wav' next?
Upvotes: 0
Views: 67
Reputation: 16878
Assuming that you are sure about this format:
string input = "CaptainNillo";
string first = listFO.FirstOrDefault(x => input.StartsWith(x));
string second = listFN.FirstOrDefault(x => input.EndsWith(x));
if (first != null && second != null)
// play first.wav and second.was
Upvotes: 1