假如 str = "abcdefghijklmn"如何 将他 按 每N个切割成数组如 N=4 切成
abcd
efgh
ijkl
mn-------------------------------
请注意 高效率,可以试试 当str 有1w、10w、100w的长度时,效率如何c#/vb/dephi/js/.... 都可以。
abcd
efgh
ijkl
mn-------------------------------
请注意 高效率,可以试试 当str 有1w、10w、100w的长度时,效率如何c#/vb/dephi/js/.... 都可以。
解决方案 »
- TreeView 双击 checkbox 只触发一次After_Check事件
- c# 关于winform如何实现像iframe这样的效果
- 如何向某应用程序菜单内添加一子项
- HttpWebRequest.GetResponse()取不到内容
- winmobile下的应用程序开发,我真的急需,谢谢了
- 马上给分!WINFORM中,TextBox哪个属性可以设置为鼠标移动到上边就显示一串字符?
- 关于new byte[] { 0x62, 0x0e }; 这0x62, 0x0e代表什么??
- 欢迎大家来讨论一下在.Net的架构实现中怎样工厂模式的使用?
- 关于datagrid的问题
- 如何在win2000的到xp的界面_高分有送
- C# 设计时怎么动态改变控件属性的可见性
- 定义“XAML”资源类
{
static void Main(string[] args)
{
string str = "abcdefghijklmn";
List<string> childs = new List<string>();
foreach (string r in Cut(str, 4))
{
Console.WriteLine(r);
} Console.ReadLine();
} static string[] Cut(string str, int len)
{
int rcount = Math.Max(0, (str.Length - 1) / len + 1);
string[] results = new string[rcount]; for (int i = 0; i < results.Length-1; i++)
{
results[i] = str.Substring(i * len, len);
}
results[results.Length - 1] = str.Substring((results.Length - 1) * len); return results;
}
}怎么CSDN的插入代码的功能时有时无啊?
{
static void Main(string[] args)
{
string str = "abcdefghijklmn";
foreach (string r in Cut(str, 4))
{
Console.WriteLine(r);
} Console.ReadLine();
} static string[] Cut(string str, int len)
{
int rcount = Math.Max(0, (str.Length - 1) / len + 1);
string[] results = new string[rcount]; for (int i = 0; i < results.Length-1; i++)
{
results[i] = str.Substring(i * len, len);
}
results[results.Length - 1] = str.Substring((results.Length - 1) * len); return results;
}
}
for循环 效率不详int count=1;
int N;
if(str.Length%N==0)
count=str.Length/N;
else
count=str.Length/N+1;
string[]s=new string[count];
for(int i=0;i<count-1;i++)
{
s[i]=str.Substring(N*i,N);
}
s[count-1]=str.Substring(N*(count-1));
{
string str = String.Join("", Enumerable.Range(1, 1000000).Select(i => "abcdefghijklmn").ToArray());
Console.WriteLine("LEN=" + str.Length); Stopwatch sw = new Stopwatch();
sw.Start(); Console.WriteLine(Cut(str, 4).Length); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalSeconds); //foreach (string r in Cut(str, 4))
//{
// Console.WriteLine(r);
//} Console.ReadLine();
}
相当于多了一个SPLIT,估计还要慢。。
int i = 0;
string s1 = "";
for (int j = 0; j < s.Length; j++)
{
if (i == 4)
{
i = 0;
}
s1 = s.Substring(i, 4);
Console.WriteLine(s1);
i++;
}
Console.WriteLine(s.Substring(s.Length-(s.Length%4),(s.Length%4)));
string s = Console.ReadLine();
int i = 0;
string s1 = "";
for (int j = 0; j < (s.Length/4); j++)
{
i = j*4;
s1 = s.Substring(i, 4);
Console.WriteLine(s1);
} Console.WriteLine(s.Substring((s.Length / 4) * 4, (s.Length % 4)));