如何从资源路径文件名获取区域性名称

本文关键字:获取 区域性 文件名 路径 资源 | 更新日期: 2023-09-27 18:17:45

拥有资源文件名例如:Employee.resx,我必须在同一文件夹中获得其他文化的列表。所以我这样想:

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);
                }
            }
        }

你们有打火机吗?我没有解决方案,例如如何从另一个字符串中得到一个字符串。我的意思是,如何从这个字符串"Employee.en-US.resx"中得到en-US,除了使用子字符串方法?任何更轻/更好的解决方案非常感谢。

如何从资源路径文件名获取区域性名称

我使用

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