Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace BBcode_Fixer
- {
- class Program
- {
- static void Main(string[] args)
- {
- string filename, fileline, matchstring, tempstring = "";
- string concatstring = "";
- Console.Write("Put text file in same location as this app\nEnter text file name (include .txt): ");
- filename = Console.ReadLine();
- Console.WriteLine(filename + "\n");
- try
- {
- using (StreamReader postcontent = new StreamReader(filename, Encoding.UTF8))
- {
- Console.WriteLine("File found!");
- Regex rx = new Regex(@"\[(td)\].*?\[(\/td)\]", RegexOptions.IgnoreCase | RegexOptions.Multiline);
- Regex tagfinder = new Regex(@"\[\S*?\]", RegexOptions.IgnoreCase);
- fileline = postcontent.ReadToEnd();
- fileline = Regex.Replace(fileline, @"((pt)\])", "px]");
- fileline = Regex.Replace(fileline, @"\[((table)\])", "[table=noborder]");
- MatchCollection rawmatches = rx.Matches(fileline);
- foreach (Match match in rawmatches)
- {
- matchstring = match.Value;
- Console.WriteLine("Old String:\n'{0}' at position {1}",
- match.Value,
- match.Index);
- Console.WriteLine(matchstring + "\n");
- if (matchstring != "[td][/td]")
- {
- matchstring = matchstring.Substring(4, matchstring.Length - 9);
- matchstring = Regex.Replace(matchstring, @"\[\/.*?\]", "");
- tempstring = Regex.Replace(matchstring, @"=.*?]", "]");
- MatchCollection tagmatches = tagfinder.Matches(tempstring);
- foreach (Match foundtag in tagmatches)
- {
- concatstring = "[/" + foundtag.Value.Substring(1, foundtag.Value.Length-1) + concatstring;
- }
- matchstring = "[td]" + matchstring + concatstring + "[/td]";
- Console.WriteLine(matchstring);
- fileline = fileline.Replace(match.Value, matchstring);
- tempstring = "";
- concatstring = "";
- matchstring = "";
- }
- }
- postcontent.Close();
- }
- StreamWriter writer = new StreamWriter("output.txt");
- writer.WriteLine(fileline);
- writer.Close();
- }
- catch (IOException e)
- {
- Console.WriteLine("The file could not be read:");
- Console.WriteLine(e.Message);
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement