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

Thành viênTrả lời
linux

ubuntu
33  bài
16-7-2009 8: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-7-2009 22:27:54
Em góp với
http://www.mediafire.com/file/ddywu35gk5j/HtmlRemoval.cs

[code]
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
*/

[/code]
---
 
awas


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

[code]
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
*/

[/code]
---


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

Lập trình không biên giới
608  bài
27-3-2010 14:0: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-7-2010 8:42:8
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 Mô tả chi tiết Ngày
NWeb.zip (1) Module đơn giản Newsweb trên Dotnetnuke v10.x.x.x10/18/2025 8:08:11 AM
vspforum.zip (11) Ma nguon vspforum ngay xua4/18/2023 6:38:37 AM
pdfjs.rar (2) pdfjs 2017 : hiển thị tốt trên iphone 11, 12, 13 không lỗi, bản 2012 sẽ lỗi trên iphone6/21/2022 11:52:48 AM
pdfjs2.rar (2) Xem file pdf bằng viewer.hml cua pdfjs (thư viện chuẩn mozilla) 2012. https://mozilla.github.io/pdf.js/getting_started/#download có thể download bản prebuild tại đây6/21/2022 11:52:04 AM
runner.zip (0) using three.js, orbitcontrol to view an object move random on map. Di chuyển 1 đồ vật ngẫu nhiên trên bản đồ, sử dụng với demo nhân viên di chuyển trong văn phòng. Toàn js download về là chạy12/5/2019 5:55:14 PM
gmap.zip (1) google map + marker7/17/2019 2:25:05 PM
vinsmarthomeservice.zip (1) java post json to api, use AsyncTask, event listener7/9/2019 5:00:10 PM
fblogin.zip (0) Login facebook bang javascript SDK7/9/2019 9:16:37 AM
autocomplete-location.zip (2) autocomplete location geo from google place, html + js7/4/2019 4:37:55 PM
WebAPI.zip (8) api for android access db (v1.0.0)7/4/2019 9:14:17 AM