Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We have 3 records of this type

!QUANT CMP=1,AMY=1,LIP=1,CBC=1,ESR=1,RF=1;!CALL W;ME6E;5466;;;!CALLED ME6E;5466
!CALLED-;08/29/2013;09:59;ar;LDKH1;;W;!CALLED1 ME6E;5466;08/28/2018;23:31;ar;LT
!CALLED1-LC1;;W;


we need the output like this

W;ME6E;5466;;;
ME6E;5466;08/29/2013;09:59;ar;LDKH1;;W;
ME6E;5466;08/28/2013;23:31;ar;LTLC1;;W;


What I have tried:

I have try this code but still it is not working properly

try
            {
                string strModuleName = string.Empty;
                strModuleName = parameters["modulename"].ToString();

 

                DataSet dsModuleData = new DataSet(strModuleName);
                DataTable dtClinicaldata = GetPatientData(connection, parameters, true);
                DataTable dtValidation = new DataTable();
                dtValidation = CreateValidationDataTable("xclinicalvalidations");
                List<string> allRows = new List<string>();
                 foreach (DataRow dr in dtClinicaldata.Rows)

 

                {
                    var uniqueOrderIds = (from r in dtClinicaldata.AsEnumerable()
                             select r["OrderId"]).Distinct().ToList();
                    
                    foreach(var i_row in uniqueOrderIds)
                    {
                        string orderid = Convert.ToString(i_row);
                        var tagcomments = (from r in dtClinicaldata.AsEnumerable()
                                      where r.Field<string>("OrderId") == orderid
                                      select r["TagComment"]).ToList();
           
                        int i = 0;
                        string strtagcomment = "";
                        foreach (var tagcomm in tagcomments)
                        {
                           string temptagcomment = Convert.ToString(tagcomm);

 

                            if (temptagcomment.Substring(0, 5).ToUpper() != "!CALL")
                            {

 

                                var indexofcall = temptagcomment.ToUpper().IndexOf("!CALL");
                                temptagcomment = temptagcomment.Substring(indexofcall);
                            }

 


                            if (temptagcomment.Substring(0, 7).ToUpper() == "!CALLED")
                            {

 

                                var callerstring = temptagcomment.Substring(0, temptagcomment.IndexOf("-"));
                                if (strtagcomment.ToUpper().Contains(callerstring.ToUpper()))
                                {
                                    temptagcomment = temptagcomment.Substring(callerstring.Length);
                                }
                                

 

                            }

 

                            temptagcomment = temptagcomment.Replace("\0", string.Empty);
                            strtagcomment = strtagcomment + temptagcomment;

 

                        }

 

                        string[] allstring = strtagcomment.ToUpper().Split(new[] { "!CALLED"}, StringSplitOptions.RemoveEmptyEntries);

 

                        foreach (var callstrin in allstring)
                        {

 

                            var fields = callstrin.Split(new char[] { ';'} ,StringSplitOptions.None);

 

                        }

 

                        //allRows.Add(strtagcomment);

 

                    }
                    
                }

 

                // Do data processing here.
                dtClinicaldata.TableName = strModuleName;
                dsModuleData.Tables.Add(dtValidation);
                dsModuleData.Tables.Add(dtClinicaldata);

 

                return dsModuleData;
            }


Anyone can help me for this.
Posted
Updated 4-May-20 6:14am
Comments
Garth J Lancaster 4-May-20 8:53am    
How many records do you receive at once ? your 'sample' suggests three (3), but can you receive 1000, 10,000 etc ?

Are these 'lines' in a file or a buffer of size <n>
BillWoodruff 4-May-20 11:14am    
to help you with this, you need to clearly describe what syntax elements in the data are invariant.

Maybe this will get you started:
string test = @"!QUANT CMP=1,AMY=1,LIP=1,CBC=1,ESR=1,RF=1;!CALL W;ME6E;5466;;;!CALLED ME6E;5466!CALLED-;08/29/2013;09:59;ar;LDKH1;;W;!CALLED1 ME6E;5466;08/28/2018;23:31;ar;LT!CALLED1-LC1;;W;";

var result = test.Split(new[] { "!CALL ", "!CALLED" }, StringSplitOptions.None);

for (int i = 1; i < result.Length; i++)
{
    Debug.Print(result[i]);
}
 
Share this answer
 
v2
Comments
Member 11776570 4-May-20 6:22am    
okay but then i have to split that data by ";" also

as i have done this

foreach (var callstrin in allstring)
{
var fields = callstrin.Split(new char[] { ';'} ,StringSplitOptions.None);
}

But still not getting proper data.
RickZeeland 4-May-20 6:42am    
I think there is some kind of link between the separated items, probably indicated by the number following CALLED.
Member 11776570 4-May-20 7:07am    
No there is not any fixed number for CALLED, there are 1 or more than it in single records values of CALLED.
Try this:
C#
string test = @"!QUANT CMP=1,AMY=1,LIP=1,CBC=1,ESR=1,RF=1;!CALL W;ME6E;5466;;;!CALLED ME6E;5466!CALLED-;08/29/2013;09:59;ar;LDKH1;;W;!CALLED1 ME6E;5466;08/28/2018;23:31;ar;LT!CALLED1-LC1;;W;";

string pattern = @"!CALLED..?";
Regex r = new Regex(pattern);
test = test.Substring(test.IndexOf("!CALL ")+6, test.Length - test.IndexOf("!CALL ")-6);
var lines = test.Split(new string[]{" "}, StringSplitOptions.RemoveEmptyEntries)
	.Select(x => r.Replace(x, ""))
	.ToList();

foreach(string s in lines)
	Console.WriteLine($"{s}\n");


Result:
W;ME6E;5466;;;

ME6E;5466;08/29/2013;09:59;ar;LDKH1;;W;

ME6E;5466;08/28/2018;23:31;ar;LTLC1;;W;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900