I have a text file that contains some hymns in a particular format.Example below.
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.
I want to extract these hymns, place them into objects and then insert them into an SQLite Database. I am trying to split them up accordingly but I am not getting anywhere so far. This is my attempt.
Main function
//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))
{
}
}
}
Model for the hymn
public class Hymn
{
public string Name { set; get; }
public List<String> Verses { set; get; }
}
When storing the verses. I need to preserve the line breaks. Is inserting a
/n
after each line before inserting the verse into object or database the best way to do this?