Advertisement
ivandrofly

Subtitle Edit - (BrtoPtTranscoder) - DataProvider

Oct 15th, 2016
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Security;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Xml.Linq;
  10.  
  11. namespace ConsoleApplication1
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             string file = @"d:\medias\desktop\listwordspt.txt";
  18.             string[] lines = File.ReadAllText(file).Split(new char[] { '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20.             var xdoc = new XDocument(new XElement("Words"));
  21.             for (int i = 0; i < lines.Length; i += 3)
  22.             {
  23.                 string wordBr = WebUtility.HtmlDecode(lines[i]).Trim();
  24.                 string wordPt = WebUtility.HtmlDecode(lines[i + 1]).Trim();
  25.  
  26.                 string[] wordsPt = wordPt.Split(',');
  27.                 string singlePtWord = string.Empty;
  28.                 //System.Web.HttpUtils
  29.                 for (int j = 0; j < wordsPt.Length; j++)
  30.                 {
  31.                     wordsPt[j] = wordsPt[j].Trim();
  32.                     if (wordsPt[j] != wordBr)
  33.                     {
  34.                         singlePtWord = wordsPt[j];
  35.                         break;
  36.                     }
  37.                 }
  38.                 // TODO: loiro/a, vendedor > vendedora, Tudo bem?
  39.  
  40.                 //string wordEn = Uri.UnescapeDataString(lines[i+2]);
  41.  
  42.  
  43.                 //wordBr = WebUtility.HtmlDecode(wordBr);
  44.                 //singlePtWord = WebUtility.HtmlDecode(singlePtWord);
  45.  
  46.  
  47.                 //wordBr = WebUtility.HtmlDecode(wordBr);
  48.                 //singlePtWord = WebUtility.HtmlDecode(singlePtWord);
  49.  
  50.                 // # Will escape chars like: "<" => "&lt;"
  51.                 //wordBr = SecurityElement.Escape(wordBr);
  52.                 //singlePtWord = SecurityElement.Escape(singlePtWord);
  53.  
  54.                 var xElement = new XElement("Word");
  55.                 xElement.Add(new XAttribute("br", wordBr));
  56.                 xElement.Add(new XAttribute("pt", singlePtWord));
  57.  
  58.                 //xdoc.Add(new XElement("Word",
  59.                 //    new XAttribute("br", wordBr),
  60.                 //    new XAttribute("pt", singlePtWord)
  61.                 //    ));
  62.  
  63.                 xdoc.Element("Words").Add(xElement);
  64.             }
  65.             xdoc.Save(@"d:\medias\desktop\listwordspt.xml");
  66.  
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement