65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Formats a string with a fixed line length.
|
|
/// </summary>
|
|
static FixLineLenght()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Formats a string with a fixed line length.
|
|
/// </summary>
|
|
/// <param name="text">String to be formatted.</param>
|
|
/// <param name="lineLenght">Maximum line length</param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
}
|
|
}
|