Geeks With Blogs
Gaurav Taneja Great dreams... never even get out of the box. It takes an uncommon amount of guts to put your dreams on the line, to hold them up and say, "How good or how bad am I?" That's where courage comes in.
WrapCharacters

 
public static string WrapCharacters(object objstr, int intNum)
        {
            if (objstr == System.DBNull.Value)
            { return ""; }

            string str = (string)objstr;
            int intLen = str.Length / intNum;
            int intInsertedChars = 0;

            if (intLen < 1)
            {
                return str;
            }
            int intStartIndex = 0;
            if (str.IndexOf(" ", 0) < intNum && str.IndexOf(" ", 0) != -1)
            {
                intStartIndex = str.IndexOf(" ", 0) + 1;
                intLen = str.Length - intStartIndex;
                intLen = intLen / intNum;
            }
            for (int intCount = 0; intCount < intLen; intCount++)
            {

                if (intCount > 0)
                    intStartIndex = intCount * intNum + 1;

                if (str.IndexOf(" ", intStartIndex) == -1 || str.IndexOf(" ", intStartIndex) > intNum)
                {
                    int intInsertIndex = (intNum * intCount) + intNum + intInsertedChars;
                    string strSubPart = "";
                    intStartIndex = intStartIndex + intInsertedChars;
                    if (intStartIndex + intNum > str.Length)
                    {
                        strSubPart = str.Substring(intStartIndex, str.Length - intStartIndex);
                    }
                    else
                    {
                        strSubPart = str.Substring(intStartIndex, intNum);
                    }
                    if (strSubPart.IndexOf(" ") == -1)
                    {
                        str = str.Insert(intInsertIndex, " ");
                        intInsertedChars++;
                    }

                }
            }
            return str.Trim();
        } Posted on Sunday, April 6, 2008 10:27 PM .Net | Back to top


Comments on this post: WrapCharacters

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Gaurav Taneja | Powered by: GeeksWithBlogs.net