Re: Strings in file
- From: "Tom" <you1@xxxxxxx>
- Date: Fri, 23 Sep 2005 22:24:01 GMT
Thanks for all help,
//Tom
"Jon Jacobs" <JonJacobsAtComcast.net> wrote in message
news:k9mdnac3M6dZgKneRVn-1A@xxxxxxxxxxxxxx
> > 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
>
>
.
- References:
- Strings in file
- From: Tom
- Re: Strings in file
- From: Maarten Wiltink
- Re: Strings in file
- From: Tom
- Re: Strings in file
- From: Jon Jacobs
- Strings in file
- Prev by Date: Re: reading a opened file
- Next by Date: Re: Strings in file
- Previous by thread: Re: Strings in file
- Next by thread: Re: Strings in file
- Index(es):