Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted
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.
Posted
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.
It's not impossible, it's Inevitable.
Posted (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 by Squirm
Posted

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?

It's not impossible, it's Inevitable.
Posted
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.

It's not impossible, it's Inevitable.
Posted (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 by AFterlife

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...