Answered by:
how.??

Question
Answers
-
I want to open a file and read text.srt and put it in a table in the same order.
Just.This example will put the file into a list of class instances. That could also be a datatable if that's what is required. There is no attempt to parse the lines, and there is minimal error checking. It shows the items in a listbox so you can confirm it is working.
Public Class Form1 Dim Titles As New List(Of SubTitle) Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim OFD As New OpenFileDialog OFD.DefaultExt = "srt" If OFD.ShowDialog() = System.Windows.Forms.DialogResult.OK Then Dim sr As New System.IO.StreamReader(OFD.FileName) Dim I As Integer = 0 Dim SubT As SubTitle Do While Not sr.EndOfStream SubT = New SubTitle Dim Seq As String = sr.ReadLine If Seq <> "" Then SubT.Sequence = CInt(Seq) SubT.TimeCode = sr.ReadLine Dim line As String Do line = sr.ReadLine If line <> "" Then SubT.Text &= line End If Loop Until line = "" Titles.Add(SubT) End If Loop sr.Close() End If ' Show the list For Each ST As SubTitle In Titles ListBox1.Items.Add(ST.tostring) Next End Sub End Class Public Class SubTitle Public Property Sequence As Integer Public Property TimeCode As String Public Property Text As String Public Overrides Function tostring() As String Return Sequence.ToString & " " & Text.Substring(0, 30) End Function End Class
I would recommend implementing the parts of the timecode as read-only properties of the class.
- Marked as answer by jamilaid Monday, September 18, 2017 1:48 AM
-
I am sorry but I can not understand this code
Public Class SubTitle Public Property Sequence As Integer Public Property TimeCode As String Public Property Text As String Public Overrides Function tostring() As String Return Sequence.ToString & " " & Text.Substring(0, 30) End Function End Class
(I am new with scripting language)
- Marked as answer by jamilaid Monday, September 18, 2017 1:47 AM
All replies
-
I want to add the subtitles with the video and control it
You will need to ask at the website for this product: http://subtitlecreator.evisolutions.nl/sc/
-
-
I want to open a file and read text.srt and put it in a table in the same order.
Just.This example will put the file into a list of class instances. That could also be a datatable if that's what is required. There is no attempt to parse the lines, and there is minimal error checking. It shows the items in a listbox so you can confirm it is working.
Public Class Form1 Dim Titles As New List(Of SubTitle) Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim OFD As New OpenFileDialog OFD.DefaultExt = "srt" If OFD.ShowDialog() = System.Windows.Forms.DialogResult.OK Then Dim sr As New System.IO.StreamReader(OFD.FileName) Dim I As Integer = 0 Dim SubT As SubTitle Do While Not sr.EndOfStream SubT = New SubTitle Dim Seq As String = sr.ReadLine If Seq <> "" Then SubT.Sequence = CInt(Seq) SubT.TimeCode = sr.ReadLine Dim line As String Do line = sr.ReadLine If line <> "" Then SubT.Text &= line End If Loop Until line = "" Titles.Add(SubT) End If Loop sr.Close() End If ' Show the list For Each ST As SubTitle In Titles ListBox1.Items.Add(ST.tostring) Next End Sub End Class Public Class SubTitle Public Property Sequence As Integer Public Property TimeCode As String Public Property Text As String Public Overrides Function tostring() As String Return Sequence.ToString & " " & Text.Substring(0, 30) End Function End Class
I would recommend implementing the parts of the timecode as read-only properties of the class.
- Marked as answer by jamilaid Monday, September 18, 2017 1:48 AM
-
I am sorry but I can not understand this code
Public Class SubTitle Public Property Sequence As Integer Public Property TimeCode As String Public Property Text As String Public Overrides Function tostring() As String Return Sequence.ToString & " " & Text.Substring(0, 30) End Function End Class
(I am new with scripting language)
- Marked as answer by jamilaid Monday, September 18, 2017 1:47 AM
-
I am sorry but I can not understand this code
That's the class definition for the object that is created from each item in the file. As the file is read the objects are created from the file information and (in this example) added to a list of objects. See:
https://msdn.microsoft.com/en-us/library/527aztek.aspxOnce you have that collection of objects you can process them how you want.
-
-
Hi Jamilaid,
Please remember to close your threads by marking helpful posts as answer, it is beneficial to other communities who have same issue.
Thanks for your understanding and support.
Best Regards,
Cherry Bu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.