c#读取.resx/.resource资源文件
来源:互联网 发布:红楼梦服饰知乎 编辑:程序博客网 时间:2024/05/17 23:33
比如有两个资源文件,en-us.resx和zh-cn.resx
public static string GetLangString(string Key, string langtype, string FilePath)
{
string filename;
switch (langtype)
{
case ''cn'': filename = "zh-cn.resources"; break;
case ''en'': filename = "en-us.resources"; break;
default: filename = "en-us.resources"; break;
}
System.Resources.ResourceReader reader = new System.Resources.ResourceReader(FilePath + filename);
string resourcetype;
byte[] resourcedata;
string result = string.Empty;
try {
reader.GetResourceData(Key, out resourcetype, out resourcedata);
//去掉第一个字节,无用
byte[] arr = new byte[resourcedata.Length - 1];
for (int i = 0; i < arr.Length; i++) {
arr[i] = resourcedata[i + 1];
}
result = System.Text.Encoding.UTF8.GetString(arr);
}
catch (Exception ex)
{
ex.ToString();
}
finally {
reader.Close();
}
return result;
}
其中en-us.resx和zh-cn.resx两个资源文件一定要先编译成en-us.resources和zh-cn.resources才能正常使用
编译工具:ResGen.exe和批处理文件.bat
.bat里面的内容:(特别是当en-us.resx和zh-cn.resx里面的字符串定义很多时,特别好用)
resgen.exe zh-cn.resx zh-cn.resources
resgen.exe en-us.resx en-us.resources
下面啰嗦一下怎么做.bat文件
1、首先建个txt文件;把内容
resgen.exe zh-cn.resx zh-cn.resources
resgen.exe en-us.resx en-us.resources
放到txt文件中,保存
2、修改txt的后缀名为.bat;
3、双击就可运行了;
备注:以上所有文件都放在一个文件夹下,若果放在不同的文件夹下,需要在.bat文件中明确指出文件路径
- C#读取资源文件Resource.resx
- c#读取.resx/.resource资源文件
- C# 使用资源文件 Resource.resx 的方法
- C# 使用资源文件 Resource.resx 的方法
- C# 使用资源文件 Resource.resx 的方法
- C# 读取Resourse多语言resx资源文件指定内容
- C# 读取.resx资源文件内字符串的方法
- c#窗口中的资源读取 Form.resx
- C# .resx资源文件访问权限
- C# wpf 使用资源文件 resx
- C#读取嵌入资源(Resx强类型资源)
- C#c#窗口中的资源读取 Form.resx
- C#调用Resources.resx资源文件中的资源
- C#调用Resources.resx资源文件中的资源
- C#调用Resources.resx资源文件中的资源
- C#调用Resources.resx资源文件中的资源
- C#调用Resources.resx资源文件中的资源
- C#读取并保存导出Resource资源文件
- Configurator
- x&(-x)如何理解
- excel导出(从数据库中)
- 延长代码执行时间
- solr
- c#读取.resx/.resource资源文件
- Runtime 控制UIButton的暴力点击
- Java常量的应用
- Flume-ng的原理和使用
- 升级mysql5.7.9后数据的恢复Table storage engine for 'supplier' doesn't have this option
- IOS9中打开另一个App
- 微软算法100道题-------跳台阶问题
- java socket InputStream 笔记
- Javascript:ajax