This commit is contained in:
2025-02-22 01:37:30 +08:00
parent 34367f433f
commit 30ca85748d
36 changed files with 2859 additions and 65 deletions
+45
View File
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.VisualScripting;
using UnityEngine;
@@ -134,5 +135,49 @@ namespace AibisDream.Utility
}
#endregion
/// <summary>
/// 拆分字符串为若干行
/// </summary>
/// <param name="input"></param>
/// <param name="maxCharsPerLine"></param>
/// <returns></returns>
public static string SplitString(string input, int maxCharsPerLine)
{
if (string.IsNullOrEmpty(input) || maxCharsPerLine <= 0)
{
return input;
}
var result = new StringBuilder();
var lines = input.Replace("<br>", "\n").Split('\n');
foreach (var line in lines)
{
var currentIndex = 0;
while (currentIndex < line.Length)
{
var length = Math.Min(maxCharsPerLine, line.Length - currentIndex);
result.Append(line.Substring(currentIndex, length));
currentIndex += length;
if (currentIndex < line.Length)
{
result.Append('\n');
}
}
result.Append('\n');
}
// Remove the last '\n' if needed
if (result.Length > 0)
{
result.Length--;
}
return result.ToString();
}
}
}