有分隔符使用split直接分割
//有分隔符的使用split函数分割
String str = "0001,0002,0003,0004,0005,0006,0007,0008,0009";
String[] strs = str.Split(',');
按照位/宽度分割 字符串-》整型数组
//字符串按照宽度转换为数组
String str1 = "0001000200030004000500060007000800091";
String str1 = {"0001", "0002", "0003", "0004", "0005"
String str1 = "0006", "0007", "0008", "0009"};
int bit = 4;
//按照4位分组除以四 //int strlen = str1.Length/bit;
//向上取整 防止不完全整除
int strlen = Convert.ToInt32(Math.Ceiling(str1.Length / (Convert.ToDouble(bit))));
Console.WriteLine("数组长度:" + strlen);
String[] str1s = new String[strlen];
for (int i = 0;i < strlen; i++)
{
if(i != strlen - 1)
{
str1s[i] = str1.Substring(i * bit, bit);
}
else
{
str1s[i] = str1.Substring(i * bit);
}
}
Console.Write("按照" + bit + "位分割后的数组:");
foreach (String s in str1s)
{
Console.Write(s + " ");
}