# 用C#实现一个数组的有关问题100分(2)

www.MyException.Cn  网友分享于：2013-01-21  浏览：14次

sorry，下面才是正确的：

List <string> list = new List <string> ();
string s = "002323001230000 ";
string[] ss = s.Split( '0 ');
foreach (string s in ss)
{
if (s != null && s != string.Empty)
{
char[] ss1 = s.ToCharArray();
}
}

ss = s.ToCharArray();
return ss;
------解决方案--------------------
sorry，下面才是正确的：

List <string> list = new List <string> ();
string s = "002323001230000 ";
string[] ss = s.Split( '0 ');
foreach (string s in ss)
{
if (s != null && s != string.Empty)
{
char[] ss1 = s.ToCharArray();
}
}

ss = s.ToCharArray();
return ss;

------解决方案--------------------
// try 了一把，嘿嘿测试通过

int[] source = new int[] {0, 0, 1, 2, 3, 0, 0, 0, 5, 8, 0, 11, 55, 0, 8, 9, 10, 0, 0};
List <List <int> > result = new List <List <int> > ();
const int separator = 0;
for (int i = 0; i < source.Length; i++) {
if (source[i] != separator) {
if (i == 0 || source[i-1] == 0) {
}
}
}

List <int[]> dst = new List <int[]> (result.Count);
foreach (List <int> a in result) {
}

// out
StringBuilder sb = new StringBuilder();
foreach (int[] a in dst) {
foreach (int n in a) {
sb.Append(n).Append( ", ");
}
sb.AppendLine();
}
HtmlPreWriter.Flush(sb);
/*
1,2,3,
5,8,
11,55,
8,9,10,
*/

------解决方案--------------------
array ary; // 这个是你要的数组
List <int> list = new List <int> ();
foreach (int i in ary)
{
if (i> 0)
}
// 这个list里面就是要的所有元素
------解决方案--------------------

Array ary; // 原数组
List <List <int> > list = new List <List <int> > ();
List <int> t = new List <int> ();
int buff = 0;
foreach (int i in ary)
{
if (i> 0)
{
}
else if (i==0 && buff> 0)
{
t.Clear();
}
buff = i;
}
return list;

// 如果要取数据，使用list[i][j]来取
// i表示取第几个数组，j表示取这个数组的第几个元素
------解决方案--------------------

StringBuilder sb = new StringBuilder();
int[] ints = { 0, 1, 2, 123, 0, 0, 0, 34, 16, 0, 7 };
foreach (int i in ints)
{
sb.Append(i.ToString());
sb.Append( ', ');
}

List <int[]> list = new List <int[]> ();
string s = sb.ToString();
string[] ss = s.Split( '0 ');
foreach (string s2 in ss)
{
if (s2 != null && s2 != string.Empty)
{
string[] ss2 = s2.Split( ', ');
List <int> ints2 = new List <int> ();