How to resolve the algorithm CSV data manipulation step by step in the Delphi programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm CSV data manipulation step by step in the Delphi programming language
Table of Contents
Problem Statement
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way.
The CSV format is flexible but somewhat ill-defined.
For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks.
Read a CSV file, change some values and save the changes back to a file. For this task we will use the following CSV file: Suggestions
Let's start with the solution:
Step by Step solution about How to resolve the algorithm CSV data manipulation step by step in the Delphi programming language
Source code in the delphi programming language
program CSV_data_manipulation;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.IoUtils,
System.Types;
type
TStringDynArrayHelper = record helper for TStringDynArray
function Sum: Integer;
end;
{ TStringDynArrayHelper }
function TStringDynArrayHelper.Sum: Integer;
var
value: string;
begin
Result := 0;
for value in self do
Result := Result + StrToIntDef(value, 0);
end;
const
FILENAME = './Data.csv';
var
i: integer;
Input, Row: TStringDynArray;
begin
Input := TFile.ReadAllLines(FILENAME);
for i := 0 to High(Input) do
begin
if i = 0 then
Input[i] := Input[i] + ',SUM'
else
begin
Row := Input[i].Split([',']);
Input[i] := Input[i] + ',' + row.Sum.ToString;
end;
end;
TFile.WriteAllLines(FILENAME, Input);
end.
You may also check:How to resolve the algorithm Run-length encoding step by step in the Sidef programming language
You may also check:How to resolve the algorithm Egyptian division step by step in the Ruby programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the C# programming language
You may also check:How to resolve the algorithm Hofstadter-Conway $10,000 sequence step by step in the Scala programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Liberty BASIC programming language