I'm trying to split a comma separated string from a Query and assign each one in a different variable:
qValidation.Close;
qValidation.SQL.Clear;
qValidation.SQL.Add('SELECT VALUE FROM PARAMETER WHERE CODPARAMETER = ''XYM'' ');
qValidation.Open;
The String I get from this Code (VALUE) is ' 12.5,45.3,33.5,67.9 '
I want to get each value and assign them in a different variable, ie:
X1 = 12.5
X2 = 45.3
X3 = 33.5
X4 = 67.9
These variables must be float type
I've read that you can use a TStringList but I don't find a Delphi4 clear way for me
TStringList
is declared in the Classes
unit. It has a CommaText
property, which will parse the input text into its Strings[]
property. For each individual string, you can convert it to Extended
using the StrToFloat()
function in the SysUtils
unit, and then assign that value to a Single
/ Double
variable as needed.
The Delphi 4 library has the necessary functionality. This is TStrings.CommaText
of unit Classes .
TStrings
is an abstract class, so must use TStringList
program ProjectTest;
{$APPTYPE CONSOLE}
uses
SysUtils, Classes;
var
vList: TStrings;
i: Integer;
begin
vList := TStringList.Create;
try
vList.CommaText := '12.5,45.3,33.5,67.9';
for i := 0 to vList.Count - 1 do
Writeln(vList[i]);
finally
vList.Free;
end;
Readln;
end.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.