Converter Html para BBCode 25.01.13 15:47
Olá,
Criei este programa que converte HTML To BBCode:
Código:
Download:
Criei este programa que converte HTML To BBCode:
Código:
- Código:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace HTMLtoBBCode
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
amostrar(toBBcode(richTextBox1.Text));
}
public string toBBcode(string desc)
{
desc = Regex.Replace(desc, @"<UL[^>]*>", "[list]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<\/UL>", "[/list]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<LI>", "[*]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<\/li>", "", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<B>", "[b]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<\/B>", "[/b]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<u>", "[u]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<\/u>", "[/u]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<i>", "[i]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<\/i>", "[/i]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<sup>", "[sup]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<\/sup>", "[/sup]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<sub>", "[sub]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<\/sub>", "[/sub]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<HR[^>]*>", "[hr]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<STRIKE>", "[strike]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<\/STRIKE>", "[/strike]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<A HREF=", "[url=", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"<\/A>", "[/url]", RegexOptions.IgnoreCase);
desc = Regex.Replace(desc, @"'>", "']", RegexOptions.IgnoreCase);
//match on image tags
var match = Regex.Matches(desc, @"<IMG[\s\S]?SRC=[^""\\]*?(.+[\s\S]?)?[^""\\]*?[\s\S]?\/?>", RegexOptions.IgnoreCase);
if (match.Count > 0)
desc = Regex.Replace(desc, match[0].ToString(), "[img]" + match[0].Groups[1].Value.Replace("\"","") + "[/img]", RegexOptions.IgnoreCase);
return desc;
}
public void amostrar(string mensagem)
{
richTextBox1.Text = mensagem;
Clipboard.SetText(richTextBox1.Text);
MessageBox.Show("Texto copiado");
}
}
}
Download:
https://mega.co.nz/#!vZcjAT5I!dgbNpE7-dDWkIyCqcOKD5SMuLmkxenWm8A2t0xN9ixg