I have a line with the following description: '|0200|4|SALGADOS|||KG|00|19051000||||17|'
I want to separate where the pipe to save data in the database.
I'm using the pos function incorrectly. But I am getting the data.
Inside the if then i will insert data into db.
ReadLn(txt, line);
if True then
if (Pos('|0200|', line)) = 1 then
begin
fArq.Add(line);
end;
if (pos('|0000|', line)) = 1 then
begin
fArq.Add(line);
end;
if (pos('|0005|', line)) = 1 then
begin
fArq.Add(line);
end;
if (pos('|C460|', line)) = 1 then
begin
fArq.Add(line);
flagCF := True;
end
else
begin
if flagCF = True then
if (pos('|C490|', line)) = 0 then
fArq.Add(line)
else
flagCF := False;
end
You can also use TStringList:
lStringList := TStringList.Create;
lStringList.delimiter := '|';
lStringList.DelimitedText := '|0200|4|SALGADOS|||KG|00|19051000||||17|';
Now you can access each field using lStringList.Items[ index ]
Note (from comments): if space characters is included in the string, set StrictDelimiter to true to avoid treating them as delimiters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With