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();
}
No comments:
Post a Comment