将字符串按指定间隔分隔
本例是用C#实现的
/// <summary>
/// 将字符串按指定间隔分隔
/// </summary>
/// <param name="strOld">要进行处理的字符串</param>
/// <param name="interval">间隔</param>
/// <returns></returns>
public static string[] SplitByInterval(string strOld, int interval)
{
try
{
string strNew = "", str = "";
int count =Convert.ToInt32( Math.Ceiling(Convert.ToDouble(strOld.Length)/ interval));
str = strOld;
for (int i = 0; i < count; i++)
{
if (str.Length > interval)
{
strNew += str.Substring(0, interval) + ";";
str = str.Substring(interval, str.Length - interval);
}
else
strNew += str;
}
return strNew.Split(';');
}
catch
{
return strOld.Split(';');
}
}
/// 将字符串按指定间隔分隔
/// </summary>
/// <param name="strOld">要进行处理的字符串</param>
/// <param name="interval">间隔</param>
/// <returns></returns>
public static string[] SplitByInterval(string strOld, int interval)
{
try
{
string strNew = "", str = "";
int count =Convert.ToInt32( Math.Ceiling(Convert.ToDouble(strOld.Length)/ interval));
str = strOld;
for (int i = 0; i < count; i++)
{
if (str.Length > interval)
{
strNew += str.Substring(0, interval) + ";";
str = str.Substring(interval, str.Length - interval);
}
else
strNew += str;
}
return strNew.Split(';');
}
catch
{
return strOld.Split(';');
}
}
作者:sy
出处:http://www.cnblogs.com/sydeveloper
QQ:522733724
本页版权归作者和博客园所有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利