This way is working but it's still text dependent one wrong ':' will crush your app,
string source = @"Transaction ID : 100000527054518 PNR No. : 6755980353 Train No. / Name : 18615 / KRIYA YOGA EXP Date of Booking : 07-Jun-2016 Class : SLEEPER CLASS Quota : GENERAL Date of Journey : 13-Jun-2016 From : HWH To : RNC Boarding At : HWH Date Of Boarding : 13-Jun-2016 Reservation Up to : RNC Distance : 416 KM Scheduled Departure : 22:10 Scheduled Arrival : 14-Jun-2016 ( 07:05 Hrs ) Total Fare : ? 500.0 & SC : ? 23.0 Adult : 2 & Child : 0 Details of Passengers S.No.Name
Age Gender Concession Status Coach Seat / Berth / WL No Current Status Coach Seat / Berth / WL No ID Type / ID No. 1 AYAN PAL 40 Male CNF S7 49(LB) CNF S7 49(LB)";
string[] sourceArray = source.Split(':');
string TransactionID = sourceArray[2].Split(' ')[0];
string pnrno = "";
string trainno = "";
string dateofbooking = "";
string classStr="";
string Quota = "";
Option 1
If you have access to the source text you should write it like that:
"Transaction ID : 100000527054518 | PNR No. : 6755980353 | ..."
after that you splitting the text by split('|')
after that the next split will be by (':') so what you will get is result[0] = type
, result[1] = value
after that in loop :
for(int i = 0 ; i < sourceArray.Count ; i++)
{
string[] resultArr = sourceArray.Split(':');
if(resultArr[0].Equals("Transaction ID")) TransactionId = resultArr[1];
else if ...
}
If you can't edit the source you need to use indexes:
int transactionIndex = source.IndexOf("Transaction ID");
int pnrIndex = source.IndexOf("PNR No.");
and from index take the value from : to : substract the next type
for example the first will be 100000527054518 PNR No. - PNR No. = 100000527054518
Option 2 and i think is the best
use regular expresion
string transactionId;
string source = @"Transaction ID : 100000527054518 PNR No. : 6755980353 Train No. / Name : 18615 / KRIYA YOGA EXP Date of Booking : 07-Jun-2016 Class : SLEEPER CLASS Quota : GENERAL Date of Journey : 13-Jun-2016 From : HWH To : RNC Boarding At : HWH Date Of Boarding : 13-Jun-2016 Reservation Up to : RNC Distance : 416 KM Scheduled Departure : 22:10 Scheduled Arrival : 14-Jun-2016 ( 07:05 Hrs ) Total Fare : ? 500.0 & SC : ? 23.0 Adult : 2 & Child : 0 Details of Passengers S.No.Name
Age Gender Concession Status Coach Seat / Berth / WL No Current Status Coach Seat / Berth / WL No ID Type / ID No. 1 AYAN PAL 40 Male CNF S7 49(LB) CNF S7 49(LB)";
Regex transactionRegex = new Regex(@"Transaction ID : [0-9]+ PNR No.");
Match match = transactionRegex.Match(source);
if (match.Success)
{
transactionId = match.Value.Replace("Transaction ID :", "").Replace("PNR No.", "");
}