/** * converter.cs * @date June 27, 2012 * @author rickbarrette@gmail.com * * Copyright 2012 Richard Barrette * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ using System; using System.IO; using System.Text.RegularExpressions; /** * This is a simple program that I will use to convert my build thread posts * from an online forum to a format that is usable by wordpress */ namespace Converter { class Program{ /** * Main Method */ static void Main(string[] args) { try { Console.WriteLine("Ricky's Build Thread Converter"); // Read the post file that is in the current working dir string FILE = @"post"; string text = File.ReadAllText(FILE); // IMG Regex regex = new Regex(@"(?\[img width=\d+ height=\d+\])(?.*)(?\[\/img\])", RegexOptions.IgnoreCase); text = regex.Replace(text, ""); // IMG regex = new Regex(@"(?\[img height=\d+ width=\d+\])(?.*)(?\[\/img\])", RegexOptions.IgnoreCase); text = regex.Replace(text, ""); // IMG regex = new Regex(@"(?\[img\])(?.*)(?\[\/img\])", RegexOptions.IgnoreCase); text = regex.Replace(text, ""); // underline [u] regex = new Regex(@"(?\[u\])(?.*)(?\[\/u\])", RegexOptions.IgnoreCase); text = regex.Replace(text, "" + "${B}" + ""); // bold [b] regex = new Regex(@"(?\[b\])(?.*)(?\[\/b\])", RegexOptions.IgnoreCase); text = regex.Replace(text, "" + "${B}" + ""); // URL [url=http://]text[/url] regex = new Regex(@"(?\[url=)(?.*)(?\])(?.*)(?\[\/url\])", RegexOptions.IgnoreCase); text = regex.Replace(text, "" + "${TEXT}" +""); // URL [url]http://[/url] regex = new Regex(@"(?\[url\])(?.*)(?\[\/url\])", RegexOptions.IgnoreCase); text = regex.Replace(text, "" + "${URL}" +""); //write the changes to the file File.WriteAllText(FILE, text); } catch { } } } }