代码如下:
static class Ulity
{
public static string[] Split(this string source,int count)
{
List<string> list = new List<string>();
string temp = string.Empty;
if(source.Length % count != 0)
source = source.PadRight(source.Length + (count-source.Length % count));
for (int i=0;i<source.Length;i=i+count)
{
for(int j=0;j<count;j++)
{
temp += source[i + j];
}
list.Add(temp);
temp = string.Empty;
}
return list.ToArray();
}
}
运行结果如下:
注:不够位数的则补空格。