public DataTable GetPnr(List<string> request)
{
DataTable dt = new DataTable();
dt.Columns.Add("PNR", typeof(string));
var output = "";
foreach (string data in request)
{
var dr = dt.NewRow();
string item = data;
int headerEndIindex = item.IndexOf("1.", 0);
if (headerEndIindex < 1)
{
return dt;
}
string header = item.Substring(0, headerEndIindex - 1);
int contentEndIindex = item.IndexOf("FXR", headerEndIindex - 1);
string contents = "";
string footer = "";
if (contentEndIindex > 0)
{
contents = item.Substring(headerEndIindex - 1, contentEndIindex - 1);
footer = item.Substring(contentEndIindex - 1);
}
if (!string.IsNullOrEmpty(contents))
{
string pattern = @"(\d?\.)";
System.Text.RegularExpressions.MatchCollection matchCollection = new System.Text.RegularExpressions.Regex(pattern).Matches(contents);
if (matchCollection.Count > 2)
{
if (!string.IsNullOrEmpty(footer))
{
pattern = @"((itinerary|ITINERARY)\s*(rebooked|REBOOKED))";
System.Text.RegularExpressions.Match match = new System.Text.RegularExpressions.Regex(pattern).Match(footer);
if (match.Success)
{
pattern = @"\s([A-Z0-9]{6})\s";
match = new System.Text.RegularExpressions.Regex(pattern).Match(header);
if (match.Success)
{
output = match.Value.Trim();
}
else
{
}
dr["PNR"] = output;
dt.Rows.Add(dr);
}
}
}
}
}
return dt;
}</string>
try this, this is a simple iteration, and there are comments telling you what is being done.
Jegan