Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //All in one:
- function ScriptCoreQuckSortAllIn(List: TStringList; Separator: string; SortingDirection:boolean): TStringList;
- var i,b: int64; TempLen, NumCounterMax: byte; ForTest: TStringList; TempString: String;
- begin
- if List.Count > 0 then begin
- ForTest := File.CreateStringList();
- for i := 0 to List.Count-1 do begin
- ForTest.Append(GetPieceSC3(List[i],Separator,0));
- TempLen := Length(ForTest[i]);
- if TempLen > NumCounterMax then NumCounterMax := TempLen;
- end;
- for i := 0 to List.Count-1 do begin
- TempString := ForTest[i];
- for b:= 1 to NumCounterMax - length(ForTest[i]) do TempString := '0' + TempString;
- List[i] := TempString+Copy(List[i],Length(ForTest[i]+Separator),Length(List[i]));
- end;
- ForTest.Free;
- With List do
- try
- BeginUpdate;
- List.Sort;
- if SortingDirection then begin
- for i := 0 to List.Count-1 do begin
- TempLen := Length(List[i]);
- for b := 1 to TempLen do begin
- TempString := List[i];
- if TempString[b] = '0' then continue else
- begin
- List[i] := Copy(TempString,b,TempLen);
- break;
- end;
- end;
- end;
- end else
- begin
- for i := 0 to List.Count-1 do begin
- TempLen := Length(List[i]);
- for b := 1 to TempLen do begin
- TempString := List[i];
- if TempString[b] = '0' then continue else
- begin
- List[i] := Copy(TempString,b,TempLen);
- break;
- end;
- end;
- List.Move(i, 0);
- end;
- end;
- Result := List;
- Finally EndUpdate
- end;
- end;
- end;
- //or separated auxiliary functions:
- function GetPieceSC3(Str, Reg: string; Number: Word): string;
- var Res: TStringList;
- begin
- try
- Res := File.CreateStringList;
- SplitRegExpr(QuoteRegExprMetaChars(Reg), Str, Res);
- Result := Res.Strings[Number];
- except
- Result := '';
- finally
- Res.Free;
- end;
- end;
- function ZeroFill(S: string; Peak: integer; IsEnabled: boolean): string;
- var i, m: integer;
- begin
- if IsEnabled then begin
- m := Peak - length(S);
- for i:= 1 to m do S := '0' + S;
- end;
- result := S;
- end;
- function ZeroRemover(s:string):string;
- var i, TempLen: integer;
- begin
- TempLen := Length(s);
- for i := 1 to TempLen do begin
- if s[i] = '0' then continue else begin
- Result := Copy(s,i,TempLen);
- exit;
- end;
- end;
- end;
- function ScriptCoreQuckSort(List: TStringList; Separator: string; SortingDirection:boolean): TStringList;
- var i: int64; TempLen, NumCounterMax: byte; ForTest: TStringList;
- begin
- if List.Count > 0 then begin
- ForTest := File.CreateStringList();
- for i := 0 to List.Count-1 do begin
- ForTest.Append(GetPieceSC32(List[i],Separator,0));
- TempLen := Length(ForTest[i]);
- if TempLen > NumCounterMax then NumCounterMax := TempLen;
- end;
- for i := 0 to List.Count-1 do List[i] := ZeroFill2(ForTest[i],NumCounterMax,true)+Copy(List[i],Length(ForTest[i]+Separator),Length(List[i]));
- ForTest.Free;
- With List do
- try
- BeginUpdate;
- List.Sort;
- if SortingDirection then for i := 0 to List.Count-1 do List[i] := ZeroRemover(List[i]) else
- begin
- for i := 0 to List.Count-1 do begin
- List[i] := ZeroRemover(List[i]);
- List.Move(i, 0);
- end;
- end;
- Result:=List;
- Finally EndUpdate
- end;
- end;
- end;
Add Comment
Please, Sign In to add comment