Click to See Complete Forum and Search --> : Help: Need to sort texct file by string in middle of lines of bunch of strings


Aaron
October 21st, 1999, 03:22 PM
Ok here is the deal. i have a large text file that i have to preserve the strings as they relate to each other on a line. However I would like to sort the file into a new file by sorting a string that is in the middle of the line of text. for example given the line of text:

aaa bbbb ffff g ggggg rrrr

I would like to sort the file based on the strings in section ffff . does anyone know how to do this.

Thanks
Aaron
If you have any question about what I want please email me.

wayne
October 21st, 1999, 09:20 PM
If all your fields are the same size such as:
a$ = "aaa bbbb ffff g ggggg rrrr"
b$ = "ccc kkkk gggg r.rrrrr tttt"
then you could do
if Mid$(a$,10,4) > Mid$(b$,10,4) then ......

if the fields vary such as
a$ = "aa bb ccc ddd"
b$ = "aaaa b ccccc dd"
then you have to come up with something different. I would have a sub routine that would extract the third element in the string and put it in another array. Then sort the new array. When you swap the new array elements then swap the origional array elements.
This is not an elegant solution would would work.