我有一个文本文件,其中包含一些特定格式的赞美诗。以下是示例。
1 Praise to the Lord
1 赞颂主,全能真神,造物之王! 我的灵啊,赞美祂,祂是你的健康和救恩! 凡听见的人,现在都要到祂的殿中来; 一同欢乐地敬拜祂!
2 赞颂主,祂奇妙地统治着万有, 祂用翅膀遮蔽你,柔和地扶持你! 难道你没有看见,祂怎样满足了你的愿望, 成就了祂所命定的吗?
3 赞颂主,祂使你的工作兴旺并保护你; 祂的慈爱和怜悯每日都在你身边。 你要再次思考全能者的大能, 如果祂以爱与你结交,祂能为你做什么。
我想提取这些圣歌,将它们放入对象中,然后插入SQLite数据库。我正在尝试相应地将它们分割,但是到目前为止我还没有进展。这是我的尝试。
主函数
//Fileinfo object wraps the file path.
var hymns = new FileInfo(@"C:HymnWords.txt");
//StreamReader reads from the existing file.
var reader = hymns.OpenText();
string line;
int number = 0;
var hymns = new List<Hymn>();
var check = false; //this is set to indicate that all the lines that are follwoing will be apart of the hymn.
while ((line = reader.ReadLine())!=null)
{
if (line.Any(char.IsLetter) && line.Any(char.IsDigit))
{
}
if (check)
{
if (line.Any(c => char.IsDigit(c) && c != 0) && !line.Any(char.IsLetter))
{
}
}
}
赞美诗的模型
public class Hymn
{
public string Name { set; get; }
public List<String> Verses { set; get; }
}
在存储诗句时,我需要保留换行符。将每行插入诗歌对象或数据库之前,在每行后面插入
是最好的方法吗?/n
\r\n
而不是/n
来保留换行符。这仅适用于将其输出为纯文本的情况。具体问题是什么?你所说的“没有进展”是什么意思? - EJC