标签:
//输入字符串,每3个截取一次,形成一个数组
static void Main(string[] args)
{
//输入字符串
Console .WriteLine ("请输入:");
string a =Convert .ToString(Console .ReadLine ());
Console.WriteLine("输入字符串的长度:"+a.Length);
//调用函数截取
string[] c =jiequ(a, 3);
//输出字符串
foreach (string b in c)
{
Console.WriteLine(b);
}
}
static string[] jiequ(string x, int y)//定义函数,输入的字符串和截取的长度
{
List <string>d=new List<string>() ;
int i = 0, j = x.Length;
while (i < x.Length && j > y)
{
d.Add(x.Substring(i, y));
i = i + y;
j = j - y;
}
d.Add(x.Substring (i,j));
return d.ToArray();
}
标签:
原文地址:http://www.cnblogs.com/xcc2016/p/5438317.html