Monday, October 16, 2006

Highlighting Search Text (Pageflakes Community)

i recently used text highlighting in a project( pageflakes community - under development), using the simplest, yet powerful class of .net called

System.Text.RegularExpressions.MatchEvaluator


Sometimes, you need to highlight the search key words ( ex.google), there are loads of methods available out there for doing so , but very simple yet power code block i have just pasted below.


private string HighLight(string inputText, string searchKey)
{
if (searchKey.Length > 0)
{
// Setup the regular expression and add the Or operator.
Regex RegExp = new Regex(searchKey.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase);
// Highlight keywords by calling the delegate each time a keyword is found.

return RegExp.Replace(inputText, new MatchEvaluator(ReplaceKeyWords));
}
return inputText;
}


public string ReplaceKeyWords(Match m)
{
return "" + m.Value + "";
}


/*CSS */
span.highlight
{
background-color : Yellow;
}



Use call this function with a search key and text to highlight and it will do the rest.


A Reader's Toolbox

The seo software highlights on keywords research to increase traffic of your website. Especially in the affiliate business, you need backups of your website so that in case of lost of data you can retrieve it. For starting a telecom related business you need pc phone for customer support with huge bandwidth and space of cheap hosting. In order to find a good server for hosting you should know best domain host must have minimum down time. Especially the wireless internet booster is necessary for boosting up your speed.

Tuesday, October 10, 2006

Quick and dirty solution for compression.

This is a real cheap solution in terms of http compression.Just to make sure the following code on page load.

protected void Page_Load(object sender, EventArgs e)
{
if(!Request.UserAgent.ToLower().Contains("konqueror"))
{
if(Request.Headers["Accept-encoding"] != null
&& Request.Headers["Accept-encoding"].Contains("gzip"))
{
Response.Filter = new GZipStream(Response.Filter,
CompressionMode.Compress, true);
Response.AppendHeader("Content-encoding", "gzip");
}
else if(Request.Headers["Accept-encoding"] != null &&
Request.Headers["Accept-encoding"].Contains("deflate"))
{
Response.Filter = new DeflateStream(Response.Filter,
CompressionMode.Compress, true);
Response.AppendHeader("Content-encoding", "deflate");
}
}
}


Source : http://www.codeproject.com/aspnet/HttpCompressionQnD.asp