public static string ConvertStr(string inputString)
{
string retVal = inputString;
retVal = retVal.Replace("&", "&");
retVal = retVal.Replace("/"", """);
retVal = retVal.Replace("<", "<");
retVal = retVal.Replace(">", ">");
retVal = retVal.Replace(" ", " ");
retVal = retVal.Replace(" ", " ");
retVal = retVal.Replace("/t", " ");
retVal = retVal.Replace("/r", "<br>");
return retVal;
}
private static string FetchURL(string strMessage)
{
string strPattern = @"(?<url>(http|ftp|mms|rstp|news|https)://(?:[/w-]+/.)+[/w-]+(?:/[/w-./?%&~=]*[^./s|,|/)|<|!])?)";
string strReplace = "<a href=/"${url}/" target=_blank>${url}</a>";
string strInput = strMessage;
string strResult;
strResult = Regex.Replace(strInput, strPattern, strReplace);
strPattern = @"(?<!http://)(?<url>www/.(?:[/w-]+/.)+[/w-]+(?:/[/w-./?%&~=]*[^./s|,|/)|<|!])?)";
strReplace = "<a href=/"http://${url}/" target=_blank>${url}</a>";
strResult = Regex.Replace(strResult, strPattern, strReplace);
return strResult;
}
public string ToUrl(string inputString)
{
string retVal = inputString;
retVal = ConvertStr(retVal);
retVal = FetchURL(retVal);
return retVal;
}