Đăng nhập | Đăng ký

Gặp gỡ những chuyên gia hàng đầu về CNTT

Diễn đàn    Dotnet framework    Xoá các thẻ html bằng regular expression

Thành viênTrả lời
linux

ubuntu
24  bài
16-07-2009 08:59:54
private string RegexReplace(string content, string pattern, string rep)
{
Regex regx = new Regex(pattern, RegexOptions.IgnoreCase);
content = regx.Replace(content, "");
return content;
}

private string RemoveSpace(string content)
{
while (content.IndexOf(" ") > -1)
content = content.Replace(" ", " ");
return content;
}

content = RegexReplace(content, "<(.|\n)*?>", " ");
content = RemoveSpace(content);
content = content.Replace("\r", "").Replace("\t", "");
content = RegexReplace(content, " ", " ");
 
tieubavuong


9  bài
16-07-2009 10:27:54
Em góp với
http://www.mediafire.com/file/ddywu35gk5j/HtmlRemoval.cs


using System;
using System.Text.RegularExpressions;

/// <summary>
/// Methods to remove HTML from strings.
/// </summary>
public static class HtmlRemoval
{
/// <summary>
/// Remove HTML from string with Regex.
/// </summary>
public static string StripTagsRegex(string source)
{
return Regex.Replace(source, "<.*?>", string.Empty);
}

/// <summary>
/// Compiled regular expression for performance.
/// </summary>
static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);

/// <summary>
/// Remove HTML from string with compiled Regex.
/// </summary>
public static string StripTagsRegexCompiled(string source)
{
return _htmlRegex.Replace(source, string.Empty);
}

/// <summary>
/// Remove HTML tags from string using char array.
/// </summary>
public static string StripTagsCharArray(string source)
{
char[] array = new char[source.Length];
int arrayIndex = 0;
bool inside = false;

for (int i = 0; i < source.Length; i++)
{
char let = source[ i ];
if (let == '<')
{
inside = true;
continue;
}
if (let == '>')
{
inside = false;
continue;
}
if (!inside)
{
array[arrayIndex] = let;
arrayIndex++;
}
}
return new string(array, 0, arrayIndex);
}
}

/**
*created by tieubavuong@updatesofts.com
*copyright TriNam, TDI, JSC
*http://trinam.com.vn
*/


---
 
awas


48  bài
20-07-2009 10:14:57
Em góp với
http://www.mediafire.com/file/ddywu35gk5j/HtmlRemoval.cs


using System;
using System.Text.RegularExpressions;

/// <summary>
/// Methods to remove HTML from strings.
/// </summary>
public static class HtmlRemoval
{
/// <summary>
/// Remove HTML from string with Regex.
/// </summary>
public static string StripTagsRegex(string source)
{
return Regex.Replace(source, "<.*?>", string.Empty);
}

/// <summary>
/// Compiled regular expression for performance.
/// </summary>
static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);

/// <summary>
/// Remove HTML from string with compiled Regex.
/// </summary>
public static string StripTagsRegexCompiled(string source)
{
return _htmlRegex.Replace(source, string.Empty);
}

/// <summary>
/// Remove HTML tags from string using char array.
/// </summary>
public static string StripTagsCharArray(string source)
{
char[] array = new char[source.Length];
int arrayIndex = 0;
bool inside = false;

for (int i = 0; i < source.Length; i++)
{
char let = source[ i ];
if (let == '<')
{
inside = true;
continue;
}
if (let == '>')
{
inside = false;
continue;
}
if (!inside)
{
array[arrayIndex] = let;
arrayIndex++;
}
}
return new string(array, 0, arrayIndex);
}
}

/**
*created by tieubavuong@updatesofts.com
*copyright TriNam, TDI, JSC
*http://trinam.com.vn
*/


---


Ổn đấy đồng chí
---
 
aspnet

Lập trình không biên giới
357  bài
27-03-2010 02:00:22
public static string RemoveHTML(string input)
{
// remove comments
input = Regex.Replace(input, "<!--(.|\\s)*?-->", string.Empty);
// remove HTML
return Regex.Replace(input, "<(.|\\s)*?>", string.Empty);
}

bổ xung thêm cho anh em
---
Coding for food
http://yenbai.awas.vn
http://tknd.vn
http://coder.awas.vn
http://awas.vn
http://bieuquyet.vn
http://webhocsinh.com
 
lyngochung


17  bài
15-07-2010 08:42:08
Các bác cho em hỏi cái:

1. Em có cái chuỗi đầu vào như đoạn sau
#subnet 172.20.192.0 netmask 255.255.192.0 {
# range 172.20.192.10 172.20.255.254;
# option routers 172.20.192.1;
#}
subnet 172.20.192.0 netmask 255.255.248.0 {
range 172.20.192.10 172.20.199.254;
option routers 172.20.192.1;
}
subnet 172.20.200.0 netmask 255.255.252.0 {
range 172.20.200.10 172.20.203.254;
option routers 172.20.200.1;
}
2. Bây giờ em muốn dùng Regular expression để lọc ra tất cả các nhóm như
subnet 172.20.192.0 netmask 255.255.248.0 {
range 172.20.192.10 172.20.199.254;
option routers 172.20.192.1;
}. Nếu trong nhóm này mà có dấu # ở trong thì không bắt lấy. Như vậy trong đoạn chuỗi trên em chỉ cần lấy 2 nhóm sau thui, mong các bác help me !
 

Chủ đề gần đây :

Cùng loại :

Tên file Người đăng Ngày Lượt
killforever.rar
Script diệt virus forever.exe (lây nhiễm qua USB) mà không cần cài lại window
aspnet 7/28/2010 6:51:30 AM 24
CSharp Coding Standards.pdf
C# Coding standard, for all user, quy tắc viết mã lập trình c# dotnet.
aspnet 6/1/2010 8:27:39 AM 197
weather_forex_gold.rar
module DNN : "vàng + thời tiết + tỷ giá ngoại tệ" của seekill
coder 3/11/2010 3:50:09 AM 343
Training DotNetNuke.zip
Tài liệu hướng dẫn cài đặt DNN, tạo module DNN đơn giản, nâng cao
quanlv 9/30/2009 9:11:36 AM 960
Viet va them 1 module don gian vao website.doc
Hướng dẫn viết module đơn giản trên DNN (word) có hình, gửi bởi vinahana
aspnet 9/18/2009 6:15:24 PM 653
Moduel NEWs Demo.zip
Một số module bao gồm: News, WorkScheduler, QA, Comment, Menu, ...
quanlv 8/22/2009 10:44:15 AM 983
MenuDNN5.rar
Menu DNN 51 Page.aspx
aspnet 7/21/2009 12:22:38 PM 740
diendan.zip
Cài đặt diễn đàn (VSP) chỉ với 4 bước.
aspnet 6/15/2009 2:18:13 AM 533
roll_updown.zip
Roll up, roll down news list using javascript, simple, easy to use.
radiogaga 6/1/2009 11:29:51 AM 210
rotator-1.0.0.rar
Auto Scroll News - tự động cuộn tin tức bằng JS
dotnetvn 5/30/2009 3:21:22 PM 289
captcha2.rar
CAPTCHA sinh ngẫu nhiên : size, font, position, color ... vẽ line gây nhiễu chống reCAPTCHA bot.
tieuphu 5/30/2009 2:34:42 PM 279
MenuDNN.zip
Menu Dọc cho DNN (Tác giả Võ Thế Quang)
biennv 5/27/2009 8:07:47 AM 684
Gioi_thieu_san_pham_unisched4.zip
Giới thiệu phần mềm xếp thời khóa biểu đại học (University Scheduling 4.0) : áp dụng cho mô hình xếp thời khóa biểu niên chế, tại các trường đại học và cao đẳng tại việt nam
khanhjin 5/12/2009 5:00:02 PM 1056
HitCounterInDatabaseASPNET.zip
HitCounter
nguyentx 4/20/2009 4:38:04 PM 287
s3Slide.rar
Slide show chuyên nghiệp, giống tintuconline.com.vn
coder 4/9/2009 9:34:41 AM 981
XMLPROG.zip
XML Programing C# dotnet
aspnet 4/4/2009 10:02:43 AM 263
menu_vnexpress.rar
Tạo menu giống vnexpress = xsl transform, C# dotnet, javascript(Toàn bộ mã nguồn).
coder 3/30/2009 10:14:50 PM 1200
DesktopModules.rar
CMS dotnetnuke + Image Library + Core CMS (DNN Data Provider) version 1.1
aspnet 3/30/2009 5:23:14 PM 895
AllUsers.zip
Hiển thị tất cả user của hệ thống Windows xp, C# source
aspnet 3/19/2009 12:29:07 PM 256
173 Funtions of Excel.XLS
173 Funtions of Excel.XLS
duc14s 3/9/2009 6:42:50 PM 246
CODERVN.NET
Công ty cổ phần công nghệ và dịch vụ AWAS
Công ty cổ phần công nghệ và dịch vụ AWAS, cổng thông tin, chính phủ điện tử, phần mềm quản lý điểm, quản lý sinh viên, http://awas.vn, http://awas.com.vn, phần mềm ứng dụng, dịch vụ công trực tuyến, thiết kế website, thiet ke web, thiết kế web, điện lực, phần mềm quản lý đào tạo, cao đẳng, đại học,cổng thông tin tích hợp, cổng thông tin điện tử, webportal, thư viện điện tử, electric library, library online, email, web, quản lý quan hệ khách hàng, CRM, dịch vụ công trực tuyến, phần mềm hành chính một cửa,