public static string[] ParseGoogleLanguages(this string str, string defaultLanguage = "auto") { string[] langs = null; foreach (string code in GoogleLanguageCodes) { if (str.StartsWith(code)) { langs = new string[2]; if (code.Length == str.Length) { langs[0] = defaultLanguage; langs[1] = code; } else { langs[0] = code; langs[1] = str.Substring(code.Length); if (!GoogleLanguageCodes.Contains(langs[1], 1)) { throw new Exception(string.Format("Unrecognised Google language code '{0}'.", langs[1])); } } break; } } if (langs == null) { throw new Exception(string.Format("Unrecognised Google language code '{0}'.", str)); } return(langs); }