Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- namespace Fixing_Subtitles
- {
- class Program
- {
- const double COEFFICIENT = 1.05;
- const int ADDITION = 5000;
- const string INPUT_FILE = @"../../../source.txt";
- const string OUTPUT_FILE = @"../../../fixed.txt";
- static void Main(string[] args)
- {
- try
- {
- Encoding encoding = Encoding.GetEncoding("windows-1251");
- StreamReader reader = new StreamReader(INPUT_FILE, encoding);
- StreamWriter writer = new StreamWriter(OUTPUT_FILE, false, encoding);
- using (reader)
- {
- using (writer)
- {
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- writer.WriteLine(FixLine(line));
- }
- }
- }
- }
- catch (IOException ex)
- {
- Console.WriteLine("Error: " + ex.Message);
- }
- Console.ReadKey();
- }
- static string FixLine(string line)
- {
- int bracketFromIndex = line.IndexOf("}");
- string startTime = line.Substring(1, bracketFromIndex - 1);
- int newStartTime = (int)(Convert.ToInt32(startTime) * COEFFICIENT + ADDITION);
- int bracketToIndex = line.IndexOf("}", bracketFromIndex + 1);
- string endTime = line.Substring(bracketFromIndex + 2, bracketToIndex - bracketFromIndex - 2);
- int newEndTime = (int)(Convert.ToInt32(endTime) * COEFFICIENT + ADDITION);
- string fixedLine = "{" + newStartTime + "}" + "{" + newEndTime + "}" + line.Substring(bracketToIndex + 1);
- return fixedLine;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement