请问 C# 如何解析 有多行值 的Properties属性文件

yours_hj 2016-09-07 06:53:21
请问类似这样的包含多行值的Propertie属性文件C#要如何解析?

revision.changes.not.supported=Current VCS does not support viewing changes by revision
line.annotation.aspect.author=Author
line.annotation.aspect.date=Date
line.annotation.aspect.revision=Revision
annotation.commit.number=Commit number

todo.handler.only.skipped=<html><body>TODO check has skipped {0,choice, 0#|1#one file|2#{0} files}.<br/>\n\
No new or edited TODO items, or items located in changed text fragments were found.</body></html>
todo.handler.only.added=<html><body>{0,choice, 0#|1#One|2#{0}} added/edited TODO {0,choice, 0#|1#item was|2#items were} found.<br/>\
Would you like to review {0,choice,1#it|2#them}?<br/>\
{1,choice, 0#|1#One file was skipped.|2#{1} files were skipped.}</body></html>
todo.handler.only.in.changed=<html><body>{0,choice, 1#One|2#{0}} TODO {0,choice, 1#item was|2#items were} found in changed fragments.<br/>\
Would you like to review {0,choice,1#it|2#them}?<br/>\
{1,choice, 0#|1#One file was skipped.|2#{1} files were skipped.}</body></html>
todo.handler.only.both=<html><body>{0, choice, 1#One|2#{0}} added/edited TODO {0,choice, 1#item|2#items},<br/>\
and {1, choice, 1#one item|2#{1} items} located in changed fragments were found.<br/>\
Would you like to review them?<br/>\
{2,choice, 0#|1#One file was skipped.|2#{2} files were skipped.}</body></html>

paths.affected.in.revision=Paths Affected in Revision {0}
...全文
280 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
哦, 应该是: 变量 n 将原来的文本进行了整理,将凡是以空格(两个空格)开头的行都跟前边的行合并在一起(中间插入一个空格)。
  • 打赏
  • 举报
回复
var n = string.Join(" ", from x in Properties.Resources.TextFile.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)
                            let y = x.StartsWith("  ") ? x : "\r\n" + x
                            select y);
var result = (from x in n.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)
                where x.Trim() != string.Empty
                select x.Split(new char[] { '=' }, 2)).ToDictionary(x => x[0], x => x[1]);
其中,变量 n 将原来的文本进行了整理,将“凡是不以空格(两个空格)开头的行都跟前边的行合并在一起(中间插入一个空格)。合并了行之后,就很容易产生 Dictionary<string,string> 结构的结果了。
  • 打赏
  • 举报
回复
假设你的文本写到资源中的文本文件类型的资源 TextFile.txt 中,可以这样获得参数:var n = string.Join(" ", from x in Properties.Resources.TextFile.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries) let y = x.StartsWith(" ") ? x : "\r\n" + x select y); var result = (from x in n.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries) where x.Trim() != string.Empty select x.Split(new char[] { '=' }, 2)).ToDictionary(x => x[0], x => x[1]);
yahle 2016-09-08
  • 打赏
  • 举报
回复
百度c#解析ini文件

111,128

社区成员

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

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

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