Wednesday 2 October 2013

Some Use full Methods in Coding

1. This method used to split string and add suffix like " ........."

   lnkTitle.Text = FormatText(lnkTitle.Text.Trim(), 200, " ");
   lblOwner.Text = FormatText(lblOwner.Text.Trim(), 100, "....");



    public string FormatText(string text, int len, string suffix)
        {
            if (len != -1 && text.Length > len)
            {
                int pos = text.LastIndexOfAny(" ,.".ToCharArray(), len);
                if (pos == -1)
                    pos = len;
                text = text.Substring(0, pos) + suffix;
            }
            return text;
        }

Out Put : like this launch new soon ...

2. This method used to return the Date Time in formatted .

 public string DateFormat(string date)
        {
            string datereturn = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(date))
                {
                    string format = "dd MMMM yyyy";
 
                    datereturn = Convert.ToDateTime(date).ToString(format);
                }
            }
            catch (Exception)
            {
            }
            return datereturn;
        }
 

No comments:

Post a Comment