Trim a string after a full word
This is some code I wrote to trim a string to the last full word after 100 characters.
if (item.Copy.Length > 100)
{
//This line gets the index of the first space starting after 100 chars
//It then cuts the string at that point and adds "..."
item.Copy = item.Copy.Substring(0, item.Copy.IndexOf(" ", 100)) + "...";
}
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home