/ Published in: C#
                    
                                        
Class to shorten text. For example for an article where people can click read more to read the whole article.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
public class CropText
{
public CropText()
{
}
public string ShortenText(string input, int MaxLenght, bool DoDots)
{
string result = input;
int InputLength = input.Length;
string lastChar = result.Substring(result.Length - 1);
if (MaxLenght < InputLength)
{
result = input.Substring(0, MaxLenght);
if (lastChar == " ")
{
result = result.Substring(0, result.Length - 1);
}
if (DoDots)
{
result += "...";
}
}
return result;
}
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                