我犯了一個程序,它從IMDB API的發佈日期和標題和.txt文件保存他們他們...我可以按日期莫名其妙順序按日期txt文件用vb.net
責令其
Imports System.IO
Imports System.Xml.Linq
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim _reg As Regex = New Regex("http://www.imdb.com/title/([A-Za-z0-9\-]+)/*?", _
RegexOptions.IgnoreCase)
Dim value As String = TextBox1.Text
Dim m As Match = _reg.Match(value)
If (m.Success) Then
Dim key As String = m.Groups(1).Value
Dim url As String = "http://mymovieapi.com/?id=" + key + "&type=xml&plot=none&episode=0&lang=en-US&aka=simple&release=simple&business=0&tech=0"
Dim Document As XDocument = XDocument.Load(url)
Dim title = Document.Root.Element("title").Value()
Dim releaseDate = Date.ParseExact(Document.Root.Element("release_date").Value,
"yyyyMMdd", System.Globalization.CultureInfo.InstalledUICulture)
TextBox2.Text = "Release Date: " & releaseDate & "/ Title: " & title
Else : TextBox2.Text = "Please use IMDB links"
End If
Button2.Enabled = True
End Sub
Private Sub Button2_Click_1(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim Writer As System.IO.StreamWriter
Writer = New System.IO.StreamWriter("C:\Users\Azer\Documents\Movies.txt", True)
Writer.Write(TextBox2.Text & vbCrLf)
Writer.Close()
Button2.Enabled = False
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
Dim Reader As System.IO.StreamReader
Reader = New System.IO.StreamReader("C:\Users\Azer\Documents\Movies.txt")
Dim tempstring As String
Do
tempstring = Reader.ReadLine()
TextBox3.Text = TextBox3.Text + tempstring + vbCrLf
Loop Until tempstring = ""
Reader.Close()
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
TextBox3.Clear()
End Sub
End Class
你只需要對它們進行一次排序?或者文本文件會隨着時間的推移而增長,並且每次修改時都需要對它進行排序?或者,您只需在從文本文件中讀回時進行排序?請詳細說明。另外,請顯示您用來做這些事情的代碼。到目前爲止,你真正要問的是,如果可以按日期排序,並且答案是肯定的。但是,如果沒有任何實際的代碼,我們不可能更具體。 – David
文本文件將隨着時間的推移而增長,並且需要每次都對其進行排序,代碼處於pastebin鏈接,因爲它太大而無法在此整體發佈 – gazerable
如果您需要重新排序整個文件(以便將其存儲在排序狀態),每次你需要讀取整個文件(進入某種類型的集合),將新內容添加到集合中,對集合進行排序,並將整個文件寫回(包括新的數據)。一般來說,數據庫是一個易於使用這種事情的_lot_。 – David