Click here to Skip to main content
12,627,681 members (33,269 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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
Updated 23-Feb-13 9: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

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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2016
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