Well, it's the week before christmas, and all thru the brain, there's nothing but cobwebs, hanging from the top of the skull to the bottom. Not that this isn't always the case, but at least this week I have an excuse

. I wanted to know, if someone would be so kind as to help me with a small portion of logic that i'm working on. What this is designed to do is take a string, regardless of length, and split it in chunks of 60 characters, but not to truncate words, or word parts. Here's the code, or at least an excerpt.
CODE
if (headerRow[4].ToString().Length > 60)
{
lenHeadString = 60;
for (int curHead = nextWritten; curHead < rowCt; curHead++)
{
curHeadString = headerRow[4].ToString().Substring(nextHeadPos, lenHeadString).TrimStart();
if (curHeadString.LastIndexOfAny(new char[] {' ', '-', '$', '/' }) != -1 && !bEnd)
curHeadString = curHeadString.Substring(0, curHeadString.LastIndexOfAny(new char[] {' ', '-', '$', '/'}));
else
{
if (bEnd)
curHeadString = headerRow[4].ToString().Substring(nextHeadPos, lenHeadString);
}
nextHeadPos += curHeadString.Length + 1;
if ((headerRow[4].ToString().Length - nextHeadPos) >= 60)
lenHeadString = 60;
else
{
lenHeadString = (headerRow[4].ToString().Length - nextHeadPos);
bEnd = true;
}
docMiddle[nextWritten++, 2] = curHeadString;
}
}
else
docMiddle[nextWritten++, 2] = headerRow[4];
return docMiddle;
To say the least, it's very cracked. The nextWritten variable is defined to be global, and is to keep track of the location in the document the next written line is. The rowCt var is defined in a calling function, and is passed into this function. The docMiddle is a 2 dimensional array that is defined in a calling function, and is passed by ref to this function. Basically, where it's failing is if the string is > 15 characters without a break, such as tracking numbers, or other run-togethers that are passed into this. In the failed test it truncated to 3 lines, as it should, but the last line was not written (4th in this case, should not have happened but it did due to the above situation), therefore causing the data that was going to be on the 4th line to be truncated. Basically the logic so far is to take the length of the string, divide it by the size of a line (60) and add one to get the row count. Then from there, parse on a max length of the specified line size, and split based on the separated characters (in this case the ' ', '-', '$', '/' character set). Like I said this works, except for in the case that it failed, string length > 15 between separators. I know this logic looks and probably is not sound, and that's another reason for posting here for suggestions.
TIA