110,535
社区成员
发帖
与我相关
我的任务
分享
string str="abcdefghijklmnopqrstuvwxyz012345678789"
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
static void UseRegExp()
{
string str = "abcdefghijklmnopqrstuvwxyzsklo0" +
",s,21010sl,x,x!@1is2902389!*189" +
"289 s091209s s s0 20 012345678789";
List<char[]> ListCharArry = new List<char[]>();
char[] c = null;
MatchCollection mc = Regex.Matches(str,@"[\s|\S]{1,5}");
for (int i = 0; i < mc.Count; i++)
{
c = mc[i].ToString().ToCharArray();
ListCharArry.Add(c);
}
}
private void button1_Click(object sender, EventArgs e)
{
string str = "abcdefghijklmnopqrstuvwxyz012345678789";
int len = (int)Math.Ceiling((double)str.Length / 5);
string[] strs = new string[len];
for (int i = 0; i < len; i++)
{
strs[i] = str.Substring(i * 5, (str.Length - i * 5 > 5) ? 5 : (str.Length - i * 5));
}
}
string str = "abcdefghijklmnopqrstuvwxyz012345678789";
int a = str.Length / 5;
if (a*5!=str.Length)
{
a++;
}
string[] arrStr=new string[a];
for (int i = 0; i < str.Length; i++)
{
arrStr[i] = str.Substring(0, 5);
str= str.Remove(0, 5);
Console.WriteLine(arrStr[i]);
if (str.Length < 5)
{
arrStr[arrStr.Length-1] = str;
}
}
for (int i = 0; i < arrStr.Length; i++)
{
Console.WriteLine(arrStr[i]);//打印结果...
}
string str = "abcdefghijklmnopqrstuvwxyz012345678789";
while (str.Length > 5)
{
Console.WriteLine(str.Substring(0, 5));
str = str.Substring(5);
}
Console.WriteLine(str);
Console.ReadLine();
using System;
using System.Collections.Generic;
using System.Diagnostics;
public class Test
{
static void Main()
{
string str = "abcdefghijklmnopqrstuvwxyz012345678789";
List<char[]> ListCharArry = new List<char[]>();
char[] c = new char[5];
for (int i = 0; i < str.Length; i++)
{
if (i % 5 == 0)
{
c = str.ToCharArray(i, 5);
ListCharArry.Add(c);
continue;
}
if (i + 5 > str.Length)
{
c = str.ToCharArray(i + 1, str.Length - i - 1);
ListCharArry.Add(c);
break;
}
}
//ListCharArry <-- 结果
Console.ReadKey();
}
}
\w{1,5}
string str = "abcdefghijklmnopqrstuvwxyz012345678789";
string[] result = Regex.Split(str, @"(?<=^(.{5})+)(?!$)");
string str = "abcdefghijklmnopqrstuvwxyz012345678789";
string str2 = "";
for (int i = 0; i < str.Length; i += 5)
{
str2 += (str2 == "" ? "" : ",") + str.Substring(i, (str.Length - 5 < i ? str.Length -i: 5));
}
string[] ar = str2.Split(',');