CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 1999
    Posts
    21

    Help: Need to sort texct file by string in middle of lines of bunch of strings

    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.


  2. #2
    Join Date
    Jun 1999
    Location
    virginia
    Posts
    16

    Re: Help: Need to sort texct file by string in middle of lines of bunch of strings

    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.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured