1个回答
展开全部
调用的时候直接string[] array= getstr("abcdef",2);
/// <summary>
/// 按照长度拆分字符串
/// </summary>
/// <param name="strs"></param>
/// <param name="len"></param>
/// <returns></returns>
public static string[] getstr(string strs,int len)
{
double i = strs.Length;
string[] myarray = new string[int.Parse(Math.Ceiling(i/len).ToString())];
for (int j=0;j < myarray.Length; j++)
{
len = len <= strs.Length ? len : strs.Length;
myarray[j] = strs.Substring(0, len);
strs = strs.Substring(len,strs.Length-len);
}
return myarray;
}
/// <summary>
/// 按照长度拆分字符串
/// </summary>
/// <param name="strs"></param>
/// <param name="len"></param>
/// <returns></returns>
public static string[] getstr(string strs,int len)
{
double i = strs.Length;
string[] myarray = new string[int.Parse(Math.Ceiling(i/len).ToString())];
for (int j=0;j < myarray.Length; j++)
{
len = len <= strs.Length ? len : strs.Length;
myarray[j] = strs.Substring(0, len);
strs = strs.Substring(len,strs.Length-len);
}
return myarray;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询