123456789101112131415161718192021222324252627282930313233343536 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace XYY.Core.Standard.ExtendMethods
- {
- public static class StringExtendMethods
- {
- public static string[] ToArray(this string str, int maxLength)
- {
- string[] arr = str.Split(' ', '.', ',');
- int page = ((str.Length + maxLength) - 1) / maxLength;
- string[] addressArr = new string[page];
- int flag = 0;
- int t = arr.Count();
- for (int i = 0; i < page; i++)
- {
- string temp = "";
- for (int j = 0; j < t; j++)
- {
- string splitor = j < t - 1 ? " " : String.Empty;//如果是最后一截,则不要加空格;
- if ((temp += arr[flag] + splitor).Length <= maxLength)
- {
- addressArr[i] += arr[flag] + splitor;
- flag++;
- }
- }
- t = arr.Count() - flag;
- }
- return addressArr;
- }
- }
- }
|