气泡
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user