using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Eugen.ESystem.Windows.Forms { public static class FixLineLenght { /// /// Formats a string with a fixed line length. /// static FixLineLenght() { } /// /// Formats a string with a fixed line length. /// /// String to be formatted. /// Maximum line length /// public static string Format(string text, int lineLenght) { int pos = 0; int spacePos = 0; string character = ""; string temp = ""; string result = ""; while (text.Length > 0) { if (text.Length <= lineLenght) { result = String.Concat(result, text); text = ""; } else { while (pos <= lineLenght) { character = text.Remove(0, pos).Remove(1); if (character == " ") { spacePos = pos + 1; } pos++; } temp = text.Remove(spacePos - 1); text = text.Remove(0, spacePos); result = String.Concat(result, temp, "\r\n"); pos = 0; spacePos = 0; } } return result; } } }