急!急!急!! c#读取properties类型文件

jiaozi123 2007-01-10 09:18:11
java中有专门的类读取properties类型文件: Properties

请问c#中有没有类似的专门类
...全文
440 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
机器人 2007-01-11
  • 打赏
  • 举报
回复
static void Main(string[] args)

{


string strFileName = "E:\\Visual Studio Project\\MessageResources.properties";




Console.WriteLine(GetPropertiesText(strFileName));



Console.Read();



}



public static string GetPropertiesText(string strFileName)

{

StringBuilder sb = new StringBuilder();

using(StreamReader sr = new StreamReader(strFileName))

{

string str = null;

while ((str = sr.ReadLine()) != null)

{

Regex regex = new Regex("(\\\\u[A-F0-9]{4})");

if(regex.IsMatch(str))

{

foreach(Match m in regex.Matches(str))

{

str = str.Replace(m.Result("$1"), GetUnicodeString(m.Result("$1").Replace("\\u", "")));

}

sb.Append(str);

}

else

{

sb.Append(str);

}

sb.Append("\n");

}

}

return sb.ToString();

}



public static string GetUnicodeString(string strInput)

{

try

{

byte[] array = new byte[2];

string str = strInput;

string s1 = str.Substring(0, 2);

string s2 = str.Substring(2);

array[0] = Convert.ToByte(s1, 16);

array[1] = Convert.ToByte(s2, 16);

return System.Text.Encoding.BigEndianUnicode.GetString(array);

}

catch(Exception e)

{

return strInput;

}

}

jiaozi123 2007-01-10
  • 打赏
  • 举报
回复
明天就得实现阿大哥,有没有代码参照一下,急死我了阿!!!!
lizhizhe2000 2007-01-10
  • 打赏
  • 举报
回复
MSDN
Ivony 2007-01-10
  • 打赏
  • 举报
回复
请参阅:
System.Configuration命名空间。
jiaozi123 2007-01-10
  • 打赏
  • 举报
回复
具体说说
CMIC 2007-01-10
  • 打赏
  • 举报
回复
反射,System.Reflection名字空间下的类
jiaozi123 2007-01-10
  • 打赏
  • 举报
回复
求各位大哥们帮忙啊!!!

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧