|
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using MessageBoard.Web;
/// <summary>
/// A utility class for formatting data
/// </summary>
public static class Utility
{
public static String GetFormattedTime(DateTime dateTime)
{
return TimeZoneUtility.ConvertToCurrentTimeZone(dateTime).ToString("MMMM dd, MM:hh tt");
}
public static String GetFormattedText(string text)
{
if (String.IsNullOrEmpty(text))
return String.Empty;
return Regex.Replace(HttpUtility.HtmlEncode(text), @"\r\n|\n|\r", "<br/>");
}
public static String GetPreviewText(object textObject)
{
string text = textObject as string;
if (String.IsNullOrEmpty(text))
return String.Empty;
//Extract around fifty words and add ...
string extract = text.Substring(0, Math.Min(150, text.Length));
if (text.Length > 150)
extract += "...";
extract = Regex.Replace(HttpUtility.HtmlEncode(extract), @"\r\n|\n|\r", "<br>");
return extract;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.