// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) Collaboris Ltd. All rights Reserved.
//
//
// The utils.
//
// --------------------------------------------------------------------------------------------------------------------
namespace Collaboris.DataAccess
{
#region Imports
using System;
using System.Web;
#endregion
///
/// The utils.
///
public class Utils
{
#region [rgn] Methods (2)
///
/// Finds a given string and enclosing it with tags provided.
///
///
/// the search is Case Insensitive
///
///
/// The source string.
///
///
/// The find string.
///
///
/// The start tag.
///
///
/// The end tag.
///
///
/// The tag string.
///
public static string TagString(string sourceString, string findString, string startTag, string endTag)
{
if (sourceString.IndexOf(findString, StringComparison.InvariantCultureIgnoreCase) == -1)
{
return sourceString;
}
string newString;
// If this is being called from a Web site, lets Decode
if (HttpContext.Current != null)
{
newString = HttpContext.Current.Server.HtmlDecode(sourceString);
}
else
{
newString = sourceString;
}
for (int i = 0; i < newString.Length; i++)
{
int pos = newString.IndexOf(findString, i, StringComparison.InvariantCultureIgnoreCase);
// if she isnt found return original string
if (pos == -1)
{
return newString;
}
int newPos = pos + startTag.Length + findString.Length;
newString = newString.Insert(pos, startTag);
newString = newString.Insert(newPos, endTag);
i = newPos + endTag.Length;
}
return sourceString;
}
#endregion [rgn]
}
}