/* * Erstellt mit SharpDevelop. * Benutzer: 001142709 * Datum: 15.05.2019 * Zeit: 08:56 * * Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern. */ using System; namespace FixLineLenght { /// /// Description of FixLineLenght. /// 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); //Bei einem Zeilenumbruch oder Wagenrücklauf eine neu Zeile beginnen if (character == "\n" || character == "\r") { spacePos = text.IndexOf("\n") + 1; break; } if (character == " ") { spacePos = pos + 1; } pos ++; } temp = text.Remove(spacePos - 1); if (temp.EndsWith("\n") || temp.EndsWith("\r")) { temp = temp.Remove(temp.Length - 1);// Ein schon enthaltenes '\n' oder '\r' am Ende de temporären Strings muss entfernt werden } text = text.Remove(0, spacePos); result = String.Concat(result, temp, "\r\n"); pos = 0; spacePos = 0; } } return result; } } }