数据绑定控件,字符串截取问题?
前台:<%#getString((DataBinder.Eval(Container.DataItem,"content")).ToString(),200)%>
后台:
protected string getString(string s, int n)
{
if (s.Length == n)
return s;
else
if (s.Length > n)
return s.Substring(0, n) + "… ";
else
if (s == " " || s == null)
return " ";
else
{
string a = s;
for (int i = 0; i <= (n - s.Length - 1); i++)
{
a += " ";
}
return a;
}
}