将动态数据保存到多维数组

时间:2014-05-06 15:54:56

标签: c# .net visual-studio-2010 .net-2.0

如何正确地将数据保存到多维数组'dataS'?

string servicios = getTextServicios();

// here an example for servicios value could be:
//"1==11==111\n2==22==222\n3==33==333"
//but the number of rows (\n) is dynamic

string[] lineas = Regex.Split(servicios, "\n");
string[] sublineas;

String[][] dataS = {};

foreach (string linea in lineas)
{
   sublineas = Regex.Split(linea, "==");
   //I want to add the lines to the array but I don't know how
   dataS += new String[]{sublineas[0], sublineas[1], sublineas[2]},
}

1 个答案:

答案 0 :(得分:1)

string[] lineas = Regex.Split(servicios, "\n");
string[] sublineas;

String[][] dataS = new string[lineas.Length][];

for(int i=0; i<lineas.Length;i++)
{
    dataS[i] = Regex.Split(lineas[i], "==");
}

另外,考虑用英语编写代码。这是一个很好的习惯。