Home > database >  Stringlist with CommaText is returning comma and spaces instead of just comma in Delphi
Stringlist with CommaText is returning comma and spaces instead of just comma in Delphi

Time:02-02

I have a string list, each string looks something like this.

2023/01/30,08:47:27, 0. 7.71,CM212-A2,03,Bad head/nozzle detect,380000,Stage No1, Head No2, Nozzle Postion5, Nozzle No0, (Single Lane), PCB ID:                , Bad head/nozzle detectReset

I am then adding that string into another list with commatext, and should be giveing a result like so

2023/01/30
08:47:27
0. 7.71
CM212-A2
03
Bad head/nozzle detect

Instead it returns

2023/01/30
08:47:27
0. 
7.71
CM212-A2
03
Bad 
head/nozzle 
detect

It seems it will create a new string for each Comma like I want, but also is creating a new string for each space which I don't want.

Adding Code just incase its needed.

procedure TForm4.Button1Click(Sender: TObject);
var
datalist : tstringlist;
eventlist : tstringlist;
  i,x: Integer;
  filename : string;
  Event : array[1..200] of TEvent;
begin
datalist := tstringlist.Create;
eventlist := tstringlist.Create;
X := 1;

//get latest file
   filename := getlastmodifiedfilename('C:\Users\tngmorse\Desktop\LockHeads\Win32\Debug\');
//end



datalist.LoadFromFile(filename);

//search for head lockout
for i := 0 to datalist.count - 1 do
begin

  if containstext(datalist[i],'Bad head') then
  begin
    memo1.Lines.Add(datalist[i]);
   // eventlist.Clear;
    eventlist.CommaText := datalist[i];
   // Event[x].Dateofevent := 'today';
    Event[x].Dateofevent := eventlist[0];    //spaces are also breaking it.
    Event[x].Timeofevent := eventlist[1];
    Event[x].Version := eventlist[2];
    Event[x].Machine := Eventlist[3];
    Event[x].EventNumber := Eventlist[4];
    Event[x].EventName := Eventlist[5];
    Event[x].TableNumber := EventList[6];
    Event[x].Table := Eventlist[7];
    Event[x].Head := Eventlist[8];
    Event[x].Nozzle := EventList[9];
    Event[x].NozzleType := Eventlist[10];
    Event[x].Lane := Eventlist[11];
    Event[x].PCBID := Eventlist[12];
    Event[x].Effect := Eventlist[13];


    memo1.Lines.Add('Date: ' Event[x].Dateofevent);
    memo1.Lines.Add('Time: ' Event[x].Timeofevent);
    memo1.Lines.Add('Machine: ' Event[x].Machine);
    memo1.Lines.Add('Event: ' Event[x].EventName);
    memo1.Lines.Add('Table: ' Event[x].Table);
    memo1.Lines.Add('Head: ' Event[x].Head);
    memo1.Lines.Add('Nozzle: ' Event[x].Nozzle);
    memo1.Lines.Add('Status: ' Event[x].Effect);



     x:=x 1;
//break down list by comma
//add to record


  end;

end;

//end

showmessage('lines: ' inttostr(datalist.Count));
datalist.Destroy;

end;

CodePudding user response:

This behavior can be controlled by the StrictDelimiter property. Set it to True to get the desired behavior.

System.Classes.TStrings.StrictDelimiter

  • Related