Advertisement
POdkovyrkinDaniil

Untitled

Feb 26th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace SystemName
  7. {
  8. class Programm
  9. {
  10. static void Main(string[] args)
  11. {
  12. SubtitleFix.SubtitleFixer();
  13. }
  14. }
  15. class SubtitleFix
  16. {
  17. private const string Value = ".";
  18. static readonly string FIRST_PATH = @"D:\Работа\Монтаж\Ролики\Аудио\в благодарность.txt";
  19. static readonly string SECOND_PATH = @"D:\Работа\Монтаж\Ролики\Аудио\в благодарность текст.txt";
  20.  
  21. public static (string,string) ReadFiles()
  22. {
  23. var FirstText = File.ReadAllText(FIRST_PATH);
  24. var SecondText = File.ReadAllText(SECOND_PATH);
  25.  
  26. return (FirstText, SecondText);
  27. }
  28.  
  29. public static void SubtitleFixer ()
  30. {
  31. string pattern = @"\d\d:\d\d:\d\d:\d\d - \d\d:\d\d:\d\d:\d\d\r\nНеизвестный";
  32. var text1 = ReadFiles().Item1;
  33. var text2 = ReadFiles().Item2;
  34. var startIndex = 0;
  35. var endIndex = 0;
  36. string result = "";
  37. var k = 0;
  38. var matches = Regex.Matches(text1, pattern);
  39. var n = 0;
  40. var currentBlock = "";
  41. for (int i = 0;i < text1.Length;i++)
  42. {
  43. if (i + 11 < text1.Length && text1.Substring(i,11) == "Неизвестный" && k + currentBlock.Length < text2.Length)
  44. {
  45. if (startIndex == 0)
  46. {
  47. startIndex = i + 11;
  48. result += matches[n].Value + "\n";
  49. n++;
  50. }
  51. else
  52. {
  53. endIndex = i - 27;
  54. var shift = text2.Substring(0, k + endIndex - startIndex + 15).LastIndexOf('.');
  55. currentBlock = text2.Substring(k, shift - k + 1) ;
  56. result = result + currentBlock + "\n\n" + matches[n].Value + "\n";
  57. k += currentBlock.Length;
  58. startIndex = endIndex;
  59. n++;
  60. }
  61. }
  62. }
  63. result += text2.Substring(k);
  64. File.WriteAllText(@"D:\Работа\Монтаж\Ролики\Аудио\в благодарность финал.txt", result);
  65. }
  66. }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement