1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-02 17:27:23 -04:00
OpenDiablo2/OpenDiablo2.Common/StringUtils.cs
Mike Bundy b4d362fc0d Change TextDictionary Population + Read char desc from there (#19)
* Change MPQ text reading

Previously checked for there to be exactly 3 commas, changed to check that line doesn't start with hash or slash (includes/comments) + that it has 3 or more commas.

This might cause issues later, but it's needed for now otherwise lines get skipped.

* Read in Not Xpac Char desc from dictionary

Also added a string utils class. How do I test with .Net?
2018-11-25 19:06:22 -05:00

39 lines
1017 B
C#

using System.Collections.Generic;
using System.Text;
namespace OpenDiablo2.Common
{
public 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;
}
}
}