<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Lazarus Pascal - Quicksort an Array of string, by the length of the strings - Delphi, Lazarus, Free Pascal				            </title>
            <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-quicksort-an-array-of-string-by-the-length-of-the-strings/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 21 Jul 2026 01:53:53 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Lazarus Pascal - Quicksort an Array of string, by the length of the strings</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-quicksort-an-array-of-string-by-the-length-of-the-strings/#post-6142</link>
                        <pubDate>Fri, 10 Oct 2025 16:46:51 +0000</pubDate>
                        <description><![CDATA[Had to write a procedure that sorts an array of strings (dynamic) by the length of the individual strings.Thought someone may find this useful:
// QuickSort array of string by string length...]]></description>
                        <content:encoded><![CDATA[<p>Had to write a procedure that sorts an array of strings (dynamic) by the length of the individual strings.<br />Thought someone may find this useful:</p>
<pre contenteditable="false">// QuickSort array of string by string length
procedure QuickSortByLength(ListOfStrings: array of string; Start: integer = -1; Stop: Integer = -1);
var
  i, j, PivotLen: Integer;
  Pivot: string;
  Temp: string;
begin
  if (Start=-1) or (Stop=-1) then
    begin
      Start := 0;
      Stop  := Length(ListOfStrings)-1;
    end;

  i := Start;
  j := Stop;
  Pivot := ListOfStrings;
  PivotLen := Length(Pivot);

  repeat
    while Length(ListOfStrings) &lt; PivotLen do Inc(i);
    while Length(ListOfStrings) &gt; PivotLen do Dec(j);

    if i &lt;= j then
      begin
        Temp := ListOfStrings;
        ListOfStrings := ListOfStrings;
        ListOfStrings := Temp;
        Inc(i);
        Dec(j);
      end;
  until i &gt; j;

  if Start &lt; j then QuickSortByLength(ListOfStrings, Start, j);
  if i &lt; Stop then QuickSortByLength(ListOfStrings, i, Stop);
end;    </pre>
<p>I did write it so that when you pass only an array, it will sort the entire array.</p>
<p>Calling this function:</p>
<pre contenteditable="false">...
var
   MyStrings : array of string;
...

// sort entire list automatically
QuickSortByLength(MyStrings);
...

// sort entire list manually
QuickSortByLength(MyStrings, 0, length(MyStrings)-1);
...

// sort only a section
QuickSortByLength(MyStrings, 5, 10);
...</pre>
<p>&nbsp;</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-quicksort-an-array-of-string-by-the-length-of-the-strings/#post-6142</guid>
                    </item>
							        </channel>
        </rss>
		