Re: Strings in file



> if you have any idea cant you help me insted?
You will need to use a variation on Chris Willig's idea of a custom sort in
a TStringList. You would use the Copy function to build the comparison
strings to use in the _Sort function. (It does not matter if you name it
_Sort or something else.) The main thing is that you would perform some test
on the List[Index1] and List[Index2] and return 0, 1, or -1. 0 if the
comparisons are equal, 1 (or any positive integer) if the string at Index1
should come after the string at Index2, -1 (or any negative integer) if the
string at Index1 should come before the string at Index2.

See Delphi Help on TStringList | CustomSort

I will use the term "sort field" which means a portion of the complete
string. That portion, or portions is the basis for comparing one complete
string with another. You would concatenate the sort fields to make the
comparison string for each complete string.

If the sort fields of the strings in the file are always at the same
locations and with the same length, then building the comparison string will
be very easy. Even if the sort fields are not at the exact same location in
every string, but they are always the same length, the comparison would
still be super simple, along the lines of:

if comparestring1 = comparestring2 then
Result := 0
else if comparestring1 > comparestring2 then
Result := 1
else
Result := -1;

In my example comparestring1 is built from the sort fields of List[Index1]
and comparestring2 is built from the sort fields of List[Index2].

If the lengths of the sort fields are not always the same, you may need to
build a number from them (using StrToIntDef, for example) and compare the
numbers.

If the positions of the sort fields are not constant then you may have to
use Pos(SomeIdentifyingPattern) to find the fields in each string. If you
can not count on a consistent pattern of characters or location to find the
sort fields in each string, then you will have to come up with a more
complex alogorithm to locate your sort fields and build your compare string.
Only you, with your familiarity with the nature of the data, would be able
to come up with the proper parsing algorithm.

In any case, once you can identify the sort fields in each string, you would
use the facilities of the CustomSort method of the TStringList.

Jon Jacobs


.



Relevant Pages

  • Re: VB6 LISTBOX problem
    ... Have a look at the code below, can you do a sort that is faster ... There are of course all sorts of ways of sorting stuff, especially stuf that is "linked together" as in your UDTs, but to prove the following code sorts it in exactly the same way that your own original code does so, by concatenating all three items of each element into a composite string exactly as you are already doing, but instead of dumping those composite strings into a ListBox it dumps them into a VB string array. ... Private Type SAFEARRAY1D ... Dim StPtr As Long, VAs String, pVAs Long ...
    (microsoft.public.vb.general.discussion)
  • C Sharp sorting considered superior to C by an order of magnitude
    ... following sort algorithms and the following points. ... its own comparision for the types bool, byte, short, int, long, ... single, double and string. ... private CheckBox CHKdeterminism; ...
    (comp.programming)
  • Re: Cant Figure Out How To Sort On Bind
    ... The sort order is not being passed as an argument, ... with the string "searchCache" to create a key for it, ... 'Assign ColumnOrder to ViewState ... Sub GetDataReader(ByVal ColumnOrder As String) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Chris Rockliffes Hofner.
    ... It looks disgusting - the original finish was a sort of pewkey ... pickups with one of those steel wire wool pan scrubbers - there was no ... strings in you have to push the trem fixture forward, ... Peter Green-ish tone. ...
    (rec.music.makers.guitar.acoustic)
  • Re: Cant Figure Out How To Sort On Bind
    ... public MySearchResults(string aa, string bb, string cc) ... MySearchResultsx1 = x as MySearchResults; ... The sort order is not being passed as an argument, ... 'Assign ColumnOrder to ViewState ...
    (microsoft.public.dotnet.framework.aspnet)