using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.ComponentModel;
namespace NearForums
{
public static class Utils
{
///
/// Crops a given text
///
/// the text to summarize
/// maximum chars allowed
/// text to be appended if the text is cropped. For example: ...
///
public static string Summarize(string value, int maxChars, string appendIfCropped)
{
if (value == null)
{
return null;
}
if (value.Length <= maxChars)
{
return value;
}
value = value.Substring(0, maxChars);
Match match = Regex.Match(value, @"^.*\b(?=[ \.])", RegexOptions.Singleline);
if (match.Success)
{
value = match.Value;
}
if (appendIfCropped != null)
{
value += appendIfCropped;
}
return value;
}
}
}