|
Don't know if these are useful?
protected string CutString (string str, int length)
{
string newString = "";
if (str! = "")
{
if (str.Length> length)
{
newString = str.Substring (0, length) + "...";
}
else
{
newString = str;
}
}
return newString;
}
Calling method:
string str = "Truncate the specified length of the string as needed";
str = CutString (str, 10);
If you are in asp.net and want to use it in data list controls (such as: DataGrid, DataList, Repeater, etc.) to achieve the effect similar to the news list described above, you can write:
<% # CutString (DataBinder.Eval (Container.DataItem, "NewTitle"). ToString (), 16)%> |
|