2011-02-28 54 views
0

我在我的數據庫中有新聞表,它包含=> Id,Title,txt。
我需要能夠從txt字段中存在的整個文本中獲取描述文本,但沒有任何代碼,如< ...>,只是一個純文本!我怎樣才能做到這一點 !?製作說明文字!

回答

1
public static string Strip(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++; 
     } 
    } 
    string text = new string(array, 0, arrayIndex); 
    return System.Text.RegularExpressions.Regex.Replace(text, @"\s+", " ").Trim(); 
} 
0

你能這麼像:

(第一獲取記錄然後添加一個屬性返回一些文本)

return Text.Length >= 100 ? Text.SubString(0,100) : Text; 
+0

這給了我第一個100字符,這可能是包含代碼。 – Rawhi 2011-02-28 09:52:26

+0

啊,在這種情況下,詹姆斯的回覆更具相關性 – WraithNath 2011-02-28 09:54:02