Click here to Skip to main content
15,884,917 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi guys...
Can anyone help me ......?

I want to develop a program that adjusts the timing of movie
subtitles with video .by editing In the start time and end time translation

i have a text file Contains the following
1
00:02:10,135 --> 00:02:13,295
إعتقدت فى ذلك الوقت أنه سيتم
.... القبض عليك

2
00:02:13,295 --> 00:02:14,855
أو كنت سأفقدك

3
00:02:14,855 --> 00:02:17,455
بسبب من ؟
 ه(روما) ؟

Thus a large number of lines

so I want to load from sub title file to listview that Containing 4 columns
num  ----   start time   -----    end time   ----    translation text 

Each column the corresponding original text file

I hope my explanation is clear of my problem....

thank you
Posted
Updated 23-Feb-13 8:40am
v3
Comments
Dave Kreskowiak 23-Feb-13 14:45pm    
Nope! You haven't said anything about what the problem is at all.
Michael Azzar 23-Feb-13 16:24pm    
First, thank you MR:Dave
my problem is how to read all lines in subtitle file to The appropriate columns ..
Dave Kreskowiak 23-Feb-13 19:46pm    
OK, so create a data structure to hold a single line of information and a collection, like List(Of myLineType), to hold all the lines. Read a line from the file and create a new object from it and add it to the list.

After you've got that, THEN you can worry about getting columns in a ListView.
Michael Azzar 25-Feb-13 6:49am    
Thanks so much for your idea certainly will help me a lot.

1 solution

you can use regular expression for this.
try following
C#
using System.IO;
using System.Text.RegularExpressions;

C#
private void ProcessSubTitleFile(string pathToFile)
{
Regex regex = new Regex(@"(?<num>\d+)\r\n(?<starttime>(\d\d:){2}\d\d,\d{3})\s-->\s(?<endtime>(\d\d:){2}\d\d,\d{3})\r\n(?<translationtext>(.|[\r\n])+?(?=\r\n\r\n|$))");            
            var textOfFile =File.ReadAllText(pathToFile);
            var matches = regex.Matches(textOfFile);
            var splits = regex.Split(textOfFile);
            foreach (Match match in matches)
            {
                var num = match.Groups["num"].Value;
                var starttime = match.Groups["starttime"].Value;
                var endtime = match.Groups["endtime"].Value;
                var translationtext = match.Groups["translationtext"].Value;                
            }
            
        }


or you can get the anonymous list

C#
private void ProcessSubTitleFile(string pathToFile)
{
   Regex regex = new Regex(@"(?<num>\d+)\r\n(?<starttime>(\d\d:){2}\d\d,\d{3})\s-->\s(?<endtime>(\d\d:){2}\d\d,\d{3})\r\n(?<translationtext>(.|[\r\n])+?(?=\r\n\r\n|$))");            
   var textOfFile =File.ReadAllText(pathToFile);
   var matches = regex.Matches(textOfFile);
   var splits = regex.Split(textOfFile);

   var items = (from System.Text.RegularExpressions.Match match in matches
       select new
       {
             num = match.Groups["num"].Value,
             starttime = match.Groups["starttime"].Value,
             endtime = match.Groups["endtime"].Value,
             translationtext = match.Groups["translationtext"].Value
       }).ToList();              
 }
 
Share this answer
 
v3
Comments
Michael Azzar 25-Feb-13 6:48am    
I got it thank you very very much MR:Tharaka for your code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900