I have a file and searching mutiple value i.e I need to search {Name,Class} and store it in a list or dictionary from the file.I need to use c#.
Ex.
Name: “ABC”
Class: “5th”
He failed in his Exam because of his poor performance.
Name : “CYS”
Class :9th
He passed in his Exam because of his good performance.
Class :10th
No comments required.
string Filename = @"ClassInfo.fo";
XmlTextReader reader = new XmlTextReader(Filename);
List<string> xmlValue = new List<string>();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine(reader.Value);
xmlValue.Add(reader.Value);
break;
}
}
string searchString = "Name :"
var foundIndices = new List<int>(xmlValue.Count);
int countValue=0;
Collection<PdfContent> pdfContent = new Collection<PdfContent>();
for (int i = 0; i < xmlValue.Count; i++)
{
if (xmlValue[i] == searchString)
{
foundIndices.Add(i);
pdfContent.Add(new PdfContent
{
Name= xmlValue[indexOfName],
Class=xmlValue[indexOfClass]
});
}
}
Please use regular expression to match pattern after reading all text in a string variable of the file
Examples for regex : http://www.regular-expressions.info/examples.html