PureSc0pe Posted March 24, 2004 Posted March 24, 2004 How would I code a button to make it alphabetize a text file? Quote It's not impossible, it's Inevitable.
*Experts* mutant Posted March 24, 2004 *Experts* Posted March 24, 2004 You mean alphabetize its contents? Its lines? If lines then, read all lines of the file into a string array and then pass in the array into the shared Sort method of the Array object which will sort it for you. Quote
PureSc0pe Posted March 24, 2004 Author Posted March 24, 2004 I need it to alphabetize the text file when I click the button. By alphabetize I mean re-organize in alphabetical order by each line. Quote It's not impossible, it's Inevitable.
Celeron Posted March 24, 2004 Posted March 24, 2004 (edited) Public Sub Alphabetize(ByVal file As String) Dim streamReader As New IO.StreamReader(file) Dim text As String = streamReader.ReadToEnd streamReader.Close() Dim line As String Dim lines() As String = Split(text, Environment.NewLine) lines.Sort(lines) Dim streamWriter As New IO.StreamWriter(file) For Each line In lines streamWriter.WriteLine(line) Next streamWriter.Close() End Sub Basically what mutant said. Edited March 26, 2004 by Squirm Quote
PureSc0pe Posted March 25, 2004 Author Posted March 25, 2004 Public Sub Alphabetize(ByVal file As String) Dim streamReader As New IO.StreamReader(TextBox2.Text) Dim text As String = StreamReader.ReadToEnd StreamReader.Close() Dim line As String Dim lines() As String = Split(text, Environment.NewLine) lines.Sort(lines) Dim StreamWriter As New IO.StreamWriter(TextBox2.Text) For Each line In lines StreamWriter.WriteLine(line) Next StreamWriter.Close() End Sub =================== This does not work...Was that the whole code or am I missing something? Quote It's not impossible, it's Inevitable.
*Experts* mutant Posted March 25, 2004 *Experts* Posted March 25, 2004 What does not work? What line? Does it throw an error or simply doesn't do what you want it to do? Quote
PureSc0pe Posted March 25, 2004 Author Posted March 25, 2004 What does not work? What line? Does it throw an error or simply doesn't do what you want it to do? There are no errors, it just doesn't do anything. I want it to alphabetize the text file and it is not doing anything. Quote It's not impossible, it's Inevitable.
AFterlife Posted March 25, 2004 Posted March 25, 2004 (edited) There are no errors' date=' it just doesn't do anything. I want it to alphabetize the text file and it is not doing anything.[/quote'] If you look back on your length of file thread i included an example an how to sort an array. The real easy way too. It will alphabetize. Edited March 25, 2004 by AFterlife Quote
PureSc0pe Posted March 26, 2004 Author Posted March 26, 2004 Problem Solved. Quote It's not impossible, it's Inevitable.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.