Home
Manage Your Code
Snippet: Crop Text remove HTML (C#)
Title: Crop Text remove HTML Language: C#
Description: Classe para realizar um Crop do Texto informado e remover o HTML do texto Views: 89
Author: Paulo Ronaldo Date Added: 5/24/2008
Copy Code  
1namespace Crop.Retorna
2{
3    using System.Text.RegularExpressions;
4
5    public class cropRetorna
6    {
7        public string CropSentence(string textCrop, int num, string trail)
8        {
9            int iMax;
10            Regex rx = new Regex("<[^>]*>");
11                   
12            textCrop = rx.Replace(textCrop, "");
13
14            iMax = num - trail.Length;
15
16            if (iMax <= 0)
17            {
18                return "";
19            }
20            else if (textCrop.Length <= num)
21            {
22                return textCrop;
23            }
24            else
25            {
26                #region Crop   ...                #endregion
37            }
38        }
39    }
40}
Usage
no DataBound do controle

if (e.Row.RowType == DataControlRowType.DataRow)
        {
            cropRetorna CR = new cropRetorna();
            e.Row.Cells[0].Text =
                CR.CropSentence(DataBinder.Eval(e.Row.DataItem, "Campo").ToString(), 100, " ...").ToString();
        }