Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 23-Feb-13 9:15am
Edited 23-Feb-13 9:40am
v3
Comments
Dave Kreskowiak at 23-Feb-13 14:45pm
   
Nope! You haven't said anything about what the problem is at all.
michael azzar at 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 at 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 at 25-Feb-13 6:49am
   
Thanks so much for your idea certainly will help me a lot.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you can use regular expression for this.
try following
using System.IO;
using System.Text.RegularExpressions;
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
 
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();              
 }
  Permalink  
v3
Comments
michael azzar at 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)

  Print Answers RSS
0 Maciej Los 495
1 Sergey Alexandrovich Kryukov 469
2 OriginalGriff 360
3 Sascha Lefévre 255
4 Abhinav S 250
0 Sergey Alexandrovich Kryukov 10,102
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076


Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100