擷取html字元長度,並保留html格式標記

2022-01-15 00:38:07 字數 888 閱讀 2779

using system;

using system.data;

using system.configuration;

using system.collections;

using system.web;

using system.web.security;

using system.web.ui;

using system.web.ui.webcontrols;

using system.web.ui.webcontrols.webparts;

using system.web.ui.htmlcontrols;

using system.text.regularexpressions;

using system.text;

public partial class test  system.web.ui.page

summary

按位元組長度擷取字串(支援擷取帶html**樣式的字串)

summary

param name=param將要擷取的字串引數param

param name=length擷取的位元組長度param

param name=end字串末尾補上的字串param

returns返回擷取後的字串returns

public string substringtohtml(string param, int length, string end)

else if (temp == '&')

else if (temp == '' && iscode)

else if (temp == ';' && ishtml)

if (!iscode && !ishtml)

}

擷取指定長度html內容,並保留html格式標記

按位元組長度擷取字串 支援擷取帶html 樣式的字串 將要擷取的字串引數 擷取的位元組長度 字串末尾補上的字串 返回擷取後的字串 public string substringtohtml string param,int length,string end else if temp else if...

擷取字元 並智慧型判斷長度是否需要擷取

獲取字元創長度 數字和字母算半個,中文漢字算乙個 function get strlength s return char length 擷取字元 function cut str str,len 擷取字元 並智慧型判斷長度是否需要擷取 function cut strdata str,len el...

關於字串長度的擷取

最近做前端,顯示某個字段內容的時候,過長,要擷取,但是中文在頁面佔兩位,英文佔1位,直接字串擷取,不能達到想要的效果,於是有了下面這個方法。c 中英文混合字串擷取指定長度 注 英文為乙個字元,中文算兩個字元 原始字串 長度 小等於0返回全部 省略號 可為空 public static string ...