我有一个文本文件,其中包含一些特定格式的赞美诗。示例如下。
1 Praise to the Lord
1
Praise to the Lord, the Almighty, the King of creation!
O my soul, praise Him, for He is thy health and salvation!
All ye who hear, now to His temple draw near;
Join ye in glad adoration!
2
Praise to the Lord, Who o'er all things so wondrously reigneth,
Shieldeth thee under His wings, yea, so gently sustaineth!
Hast thou not seen how thy desires e'er have been
Granted in what He ordaineth?
3
Praise to the Lord, who doth prosper thy work and defend thee;
Surely His goodness and mercy here daily attend thee.
Ponder anew what the Almighty can do,
If with His love He befriend thee.
我想提取这些赞美诗,将它们放入对象中,然后将它们插入 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
在将经文插入对象或数据库之前的每一行之后,这样做的最佳方法是什么?