How to sort with StreamReader method?

cciedreamer

New member
Joined
Feb 26, 2010
Messages
2
Programming Experience
Beginner
Hello

what a cool forum. Thank you for allowing me to join.

hello everyone. Just a litte about me. Well, I am not intermediate
but I am not a beginner either. And I like to try to do my own work as much as I can. I am not a mooch just to let you know.

Okay,
I made this tiny program that pulls in a text file data with StreamReader
method. Okay how can I sort the text file alpahbetically A - Z while it comes in is this possible? and how do I do it, I have no clue. Any good examples out there I can look at or any suggestions. Thanks

VB.NET:
Private Sub mn_ViewHolidays_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mn_ViewHolidays.Click
        Dim FILE_NAME As String = "C:\test.txt"

        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
            txt_HolidayView.Text = objReader.ReadToEnd
            objReader.Close()
        Else
            MsgBox("File Does Not Exist")
        End If
    End Sub
 
You might want to explain first, WHAT you want to sort. How does the content of the file look?

And if you use "ReadToEnd" you can not sort anything, because the result is a single string. And you obviously cant sort a single object.
 
List(Of T) has a sort method. If you read each line ( .Readline() ) and add them to a List(Of T) you can then sort
VB.NET:
Dim myList As New List(Of String)
    Using sr As New StreamReader("")
      While Not sr.EndOfStream
        myList.Add(sr.ReadLine)
      End While
    End Using
myList.Sort()
 
newguy
wow thanks great code..I really appreciate you showing me that
It is so cool to see so many different types/ways of doing code
thank you for your time..
"Close Counts for Horseshoes, Handgranades, and Nuclear Missiles! "
that is so freaking funny hahahha ;)

I like that "newguy" hahaha.

Well I hope to be as good as you newguy someday..I hope..

thanks a lot for your insight..

and you picoflop haah you have a cool name too.
and thanks for your help I appreciate you taking the time to help me
cheers
 
Back
Top