c# 如何4个4个的存进数组
答案:1 悬赏:0 手机版
解决时间 2021-03-24 16:54
- 提问者网友:温旧梦泪无声
- 2021-03-24 04:19
c# 如何4个4个的存进数组
最佳答案
- 五星知识达人网友:行路难
- 2021-03-24 04:49
static void Main(string[] args)
{
string test = "1234567890";
string[] newArray = NewArray(test, 4);
if(newArray!=null)
foreach (string item in newArray)
{
Console.Write(item + " ");
}
Console.ReadKey();
}
static string[] NewArray(string str, int groupCount)
{
string[] newArray = null;
int count = str.Length / groupCount;
if (count < 1) return newArray;
newArray = new string[count];
for (int i = 0; i < count; i++)
{
newArray[i] = str.Substring(i * groupCount, groupCount);
}
return newArray;
}
{
string test = "1234567890";
string[] newArray = NewArray(test, 4);
if(newArray!=null)
foreach (string item in newArray)
{
Console.Write(item + " ");
}
Console.ReadKey();
}
static string[] NewArray(string str, int groupCount)
{
string[] newArray = null;
int count = str.Length / groupCount;
if (count < 1) return newArray;
newArray = new string[count];
for (int i = 0; i < count; i++)
{
newArray[i] = str.Substring(i * groupCount, groupCount);
}
return newArray;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯