Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace SystemName
- {
- class Programm
- {
- static void Main(string[] args)
- {
- SubtitleFix.SubtitleFixer();
- }
- }
- class SubtitleFix
- {
- private const string Value = ".";
- static readonly string FIRST_PATH = @"D:\Работа\Монтаж\Ролики\Аудио\в благодарность.txt";
- static readonly string SECOND_PATH = @"D:\Работа\Монтаж\Ролики\Аудио\в благодарность текст.txt";
- public static (string,string) ReadFiles()
- {
- var FirstText = File.ReadAllText(FIRST_PATH);
- var SecondText = File.ReadAllText(SECOND_PATH);
- return (FirstText, SecondText);
- }
- public static void SubtitleFixer ()
- {
- string pattern = @"\d\d:\d\d:\d\d:\d\d - \d\d:\d\d:\d\d:\d\d\r\nНеизвестный";
- var text1 = ReadFiles().Item1;
- var text2 = ReadFiles().Item2;
- var startIndex = 0;
- var endIndex = 0;
- string result = "";
- var k = 0;
- var matches = Regex.Matches(text1, pattern);
- var n = 0;
- var currentBlock = "";
- for (int i = 0;i < text1.Length;i++)
- {
- if (i + 11 < text1.Length && text1.Substring(i,11) == "Неизвестный" && k + currentBlock.Length < text2.Length)
- {
- if (startIndex == 0)
- {
- startIndex = i + 11;
- result += matches[n].Value + "\n";
- n++;
- }
- else
- {
- endIndex = i - 27;
- var shift = text2.Substring(0, k + endIndex - startIndex + 15).LastIndexOf('.');
- currentBlock = text2.Substring(k, shift - k + 1) ;
- result = result + currentBlock + "\n\n" + matches[n].Value + "\n";
- k += currentBlock.Length;
- startIndex = endIndex;
- n++;
- }
- }
- }
- result += text2.Substring(k);
- File.WriteAllText(@"D:\Работа\Монтаж\Ролики\Аудио\в благодарность финал.txt", result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement