using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public static string Ubb(string Htmlstring) {
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase); Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
return Htmlstring;
}
private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text!=""){
FileStream fileOpen = new FileStream(textBox1.Text,FileMode.Open);
webBrowser1.DocumentStream = fileOpen;
// webBrowser1.DocumentText = fileOpen;
} // string a = "Ubb";
//webBrowser1.DocumentStream=a;
//System.Web.HttpContext.Current.Response.Write(a);
} private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.RestoreDirectory = true;
open.FilterIndex = 1;
open.Filter = "文本文件(*.txt)|*.*|html文件(*html)|*.html|所有文件|*.*";
open.InitialDirectory = "c:\\";
if(open.ShowDialog()==DialogResult.OK){
textBox1.Text = open.FileName;
}
} private void Form1_Load(object sender, EventArgs e)
{
}
} }有高手能告诉下吗,正则表达好像没出错!!就是我点击按钮的时候怎么调用这个方法!!!!着急啊!!!
现在是显示HTML的内容但是标签还在,这个方法一直用上!!求高手解答!!!!!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public static string Ubb(string Htmlstring) {
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase); Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
return Htmlstring;
}
private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text!=""){
FileStream fileOpen = new FileStream(textBox1.Text,FileMode.Open);
webBrowser1.DocumentStream = fileOpen;
// webBrowser1.DocumentText = fileOpen;
} // string a = "Ubb";
//webBrowser1.DocumentStream=a;
//System.Web.HttpContext.Current.Response.Write(a);
} private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.RestoreDirectory = true;
open.FilterIndex = 1;
open.Filter = "文本文件(*.txt)|*.*|html文件(*html)|*.html|所有文件|*.*";
open.InitialDirectory = "c:\\";
if(open.ShowDialog()==DialogResult.OK){
textBox1.Text = open.FileName;
}
} private void Form1_Load(object sender, EventArgs e)
{
}
} }有高手能告诉下吗,正则表达好像没出错!!就是我点击按钮的时候怎么调用这个方法!!!!着急啊!!!
现在是显示HTML的内容但是标签还在,这个方法一直用上!!求高手解答!!!!!
StreamReader sr = new StreamReader(fs);
string strHtml = sr.ReadToEnd();
strHtml= Ubb(trHtml);
webBrowser1.DocumentText = strHtml;
我对winfrom太不理解了!!你能讲明细下吗!这fs和trHrml哪来的啊
___________________________________
我写的vs2005源代码管理器
http://topic.csdn.net/u/20091203/10/ca40b678-5443-4a18-a9f6-fad9051d0797.html
StreamReader sr = new StreamReader(fileOpen);
string strHtml = sr.ReadToEnd();
strHtml= Ubb(strHtml);
webBrowser1.DocumentText = strHtml; fs就是文件流,下面那个是写错名字了。
Htmlstring=HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();未将对象引用设置到对象的实例,实在解决不明白了!!