限制标题字符串的长度,超过长度的截取并加上"..."

///


/// 限制标题字符串的长度,超过长度的截取并加上"..."
///

/// datatable对象
/// 处理后的datatable对象
private void SetTitleLength(DataTable table)
{
const int TITLE_MAX_LENGTH = 5;
for (int i = 0; i < table.Rows.Count; i++)
{
DataRow row = table.Rows[i];
if (!row.IsNull("neirong"))
{
string strTitle = row["neirong"].ToString();
if (strTitle.Length > TITLE_MAX_LENGTH)
{
row["neirong"] = strTitle.Substring(0, TITLE_MAX_LENGTH) + "...";
}
}
}
}

转载于:https://www.cnblogs.com/otsf/p/8515052.html

你可能感兴趣的:(限制标题字符串的长度,超过长度的截取并加上"...")