private static int BreakLine(string text, int pos, int max) { // Find last whitespace in line int i = max; while (i >= 0 && !Char.IsWhiteSpace(text[pos + i])) i--; // If no whitespace found, break at maximum length if (i < 0) return max; // Find start of whitespace while (i >= 0 && Char.IsWhiteSpace(text[pos + i])) i--; // Return length of text before whitespace return i + 1; }//BrakeLine