Pages

Tuesday, September 17, 2013

Function to convert the text into the link - C#



 string str="dsdhd sdsdhsd http://www.google.com dssdd sdd http://yahoo.co.in";

 string output=formattedData(str);              // call function



 public string formattedData(string str)
    {
        try
        {
            string full = string.Empty;
            string temp = string.Empty;
            string[] arra = str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string o in arra)
            {
                temp = o;

                if (o.ToString().ToLower().Contains("http://") == true)
                {
                    temp = "<a target=\"_blank\" href=" + "\"" + o.ToString() + "\"" + ">" + o.ToString() + "</a>";
                }
                full = full + " " + temp;
            }
            return full.ToString().Trim();
        }
        catch (Exception ex)
        {
            return " ";
        }
    }




OUTPUT:

dsdhd sdsdhsd http://www.google.com dssdd sdd http://yahoo.co.in

No comments:

Post a Comment