mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-10-03 00:28:40 -04:00
39 lines
1.0 KiB
C#
39 lines
1.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace OpenDiablo2.Common
|
|
{
|
|
public static class StringUtils
|
|
{
|
|
public static List<string> SplitIntoLinesWithMaxWidth(string fullSentence, int maxChars)
|
|
{
|
|
var lines = new List<string>();
|
|
var line = new StringBuilder();
|
|
var totalLength = 0;
|
|
var words = fullSentence.Split(' ');
|
|
foreach (var word in words)
|
|
{
|
|
totalLength += 1 + word.Length;
|
|
if (totalLength > maxChars)
|
|
{
|
|
totalLength = word.Length;
|
|
lines.Add(line.ToString());
|
|
line = new StringBuilder();
|
|
}
|
|
else
|
|
{
|
|
line.Append(' ');
|
|
}
|
|
|
|
line.Append(word);
|
|
}
|
|
|
|
if (line.Length > 0)
|
|
{
|
|
lines.Add(line.ToString());
|
|
}
|
|
|
|
return lines;
|
|
}
|
|
}
|
|
} |