Jannik worked for a company known for a line of building products
. They were an international company, which meant they had to make sure their website supported multiple languages. They embedded this information into the URL, eg http://company.com/eng/orders
.
They tracked the list of valid languages in an array:
/// <summary>
/// A list of supported folder names
/// </summary>
public static string[] VALID_FOLDERS = new string[]
{
"eng", // English
"deu", // German
"fra", // French
"jpn", // Japanese
"kor", // Korean
"dan", // Danish
"fin", // Finnish
"swe", // Swedish
"nor", // Norwegian
"dut", // Dutch
"spa" // Spanish
};
One of Jannik’s co-workers was given a simple task- given a URL, make sure the URL contains a valid language string. His solution was to compare… “brick by brick”.
public static string GetLanguageFromUrl (string Url)
{
foreach (string s in VALID_FOLDERS)
{
if (s[0] == Url[1])
{
if (s[1] == Url[2])
{
if (s[2] == Url[3])
{
return s;
}
}
}
}
return string.Empty;
}
[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!