简体   繁体   中英

How to get culture name from a resource path file name

Having a resource file name ex: Employee.resx I must get a list with other cultures in same folder. So I thought like this:

private void GetExtraCultures(string resxFileDirectory, string neutralResxFileName)
        {
            string resxFullPath = resxFileDirectory + Path.DirectorySeparatorChar;
            string[] extraResxCulturesPath = Directory.GetFiles(resxFullPath, neutralResxFileName.Replace(".resx", "") + "*" + ".resx");
            List<string> extraResxCulturesList = new List<string>();

            foreach (string extraCulturePath in extraResxCulturesPath)
            {
                string currentFileName = Path.GetFileName(extraCulturePath);
                if (currentFileName != neutralResxFileName)
                {
                    string t = currentFileName.Substring(currentFileName.IndexOf(".") + 1);
                    string tt = t.Substring(0, t.IndexOf("."));

                    extraResxCulturesList.Add(tt);
                }
            }
        }

Do you have any lighter solution? I am out of solution for example for how to get a string out of another. I mean, how to get en-US from this string "Employee.en-US.resx" except using substring method? Any lighter/ better solution very much appreciated.

I am using

string file = @"i18n\i18n.de-DE.resx";
string culture = Path.GetExtension(Path.GetFileNameWithoutExtension(file)).Substring(1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM