Search code examples
c#arrayssplitcrystal-reportsdelimiter

Split crystal report text field with more than one delimiter and load on different field


I have saved the following text which represent patient prescription in a table field ABZ SYP 10MLS-5-40-1-b.d-5-10-400,ABZ TAB 400MG-10-5-0.5-t.i.d-10-30-75, and I don't want it to load in a single crystal report field. I want them to be loaded in different fields like first split on comma, like below

ABZ SYP 10MLS-5-40-1-b.d-5-10-400,
ABZ TAB 400MG-10-5-0.5-t.i.d-10-30-75,
ACTAL SYP 5LITRES-6-50-1-o.d-10-10-500,

then split on hyphen - and have below final output on different fields ABZ SYP 10MLS unit cost 40 1 frequency b.d qty 5 days 10 cost 400 ABZ TAB 400MG unit cost 5 unit 0.5 frequency t.i.d qty 10 days 30 cost 75

below is my code can't seem to make it work

stringvar array MYARRAY:=  Split({Table.Treatment}, "-");
stringvar array numbers;`enter code here`
Redim numbers[Ubound(MYARRAY)];
numberVar i ;
  for i :=1  to ubound(MYARRAY)   do  (
//MYARRAY[1][i] //&" "& MYARRAY[5][i]&" "& MYARRAY[6][i]&" Days,";
//numbers[i] := (MYARRAY[1]) &" "& (MYARRAY[5])&" "& (MYARRAY[6])&" Days,"
//numbers[i] := Tostring(MYARRAY[1][i])
);
 // 
numbers;

Solution

  • thank you for responses i was able to yield the results i needed by adjusting code as follows with help of your responses

        local stringvar array MYARRAY:=  Split({Table.Treatment}, ",");
    numberVar i ;
     Stringvar output;
     //output:
      for i :=1  to ubound(MYARRAY)   do  (
    Stringvar array AfterSplit2:=Split(MYARRAY[i], "-");
    output:=output + AfterSplit2[1] & space(1)& AfterSplit2[5] &" Days "& AfterSplit2[6]&" Qty "& AfterSplit2[7] & ChrW(10)
    );
    output
    

    enter image description here