I suggest further improvement:
function CutLoc(aInt: Integer; const aStr: string): Integer;
The keyword const should be for aStr. Because unmodified string parameters will be optimized if it used with const keyword. And for Integer parameters, the const keyword is not very useful.
The line #11 should be:
Str := Str2[Idx];
And line #5 should be:
Str : Char;
A : string;
B : String
,
,
,
A := 'ABCDEF';
B:= Copy(A,1,1);
Both A and B are treated as a string;
But B := A(Idx);
the value of A(Idx) is now a Char so if I change B to a Char it should work.
Did anybody suggest using TStringList.CommaText?Didn't know about it :o
9 items:
"LAN"
"YSSY"
"NZAA"
"B789_LAN_LATAM"
"0010"
"LA800"
"CC-BGA"
"0"
"0325"
JLWest, did you consider Bart's suggestion with TStringList in reply #14? It works perfectly:
program Project1; uses Classes; const s = 'LAN , YSSY , NZAA , B789_LAN_LATAM , 0010 , LA800 , CC-BGA , 0 ,0325'; var i: Integer; L: TStringList; begin L := TStringList.Create; try L.CommaText := s; WriteLn(L.count, ' items:'); for i:=0 to L.Count-1 do WriteLn('"', L[i], '"'); finally L.Free; end; ReadLn; end.
Output (the quotes were added to show whether the spaces are trimmed correctly):Quote9 items:
"LAN"
"YSSY"
"NZAA"
"B789_LAN_LATAM"
"0010"
"LA800"
"CC-BGA"
"0"
"0325"
L := TStringList.Create;This actually is correct although the line "Field := L" looks wrong. This is because the forum software swallows the character i enclosed by square brackets. I am repeating your code here using the index j instead of i to demonstrate that it does not contain a line "Field := L"
try
L.CommaText := TFRecord;
for i:=0 to L.Count-1 do Begin <----------------- going thru the list of fields
Field := L; <-------------------- Field is a String
ValidField := VerifyField(Field); <------------ValidField is a Boolean
end; <----------------------------------------------End of list
finally
L.Free;