using System;
using System.Collections.Generic;
using System.Text;
namespace Forest.Util.Security
{
/// <summary>
/// 文本工具类
/// </summary>
public class TextHelper
{
private readonly static string emptyString = string.Empty;
private static readonly Encoding encoding = Encoding.Default;
private static readonly Encoding encodingUTF8 = Encoding.UTF8;
/// <summary>
/// 按指定(字节)长度分段截取字符串
/// </summary>
/// <param name="sourceString">源字符串</param>
/// <param name="limitLengths">限制字节长度集合[每段限制字节长度]</param>
/// <param name="isRecommend">使用推荐</param>
/// <returns></returns>
public static List<string> SubCutoutString(string sourceString, List<int> limitLengths, bool isRecommend = true)
{
var result = new List<string>();
try
{
var cutoutLength = 0;
var needCut = true;
sourceString = sourceString.Trim();
foreach (var limitLength in limitLengths)
{
var tempString = emptyString;
if (needCut)
按指定(字节)长度分段截取字符串
于 2021-08-24 14:44:27 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)