好的,所以我有一个看起来像这样的字符串数组:
myArray[0] = "a0,b0,c0,d0"
myArray[1] = "a1,b1,c1,d1"
myArray[2] = "a2,b2,c2,d2"
myArray[3] = "a3,b3,c3,d3"
etc...
我想创建一个使用每个元素的第一部分作为“键”的多维数组。简而言之:
myMultiArray:
x/y| 0 | 1 | 2 | 3 |
------------------------
0 | "a0" | "a1" | "a2" | "a3" |
1 | "b0" | "b1" | "b2" | "b3" |
2 | "c0" | "c1" | "c2" | "c3" |
3 | "d0" | "d1" | "d2" | "d3" |
这就是我所拥有的:
private String[,] resultsParser(String[] inputArray)
{
String[] splittedString = null;
String[,] outputString = null;
for (int i = 0; i < inputArray.Length; i++ )
{
splitString = inputArray[i].Split(',');
for (int j = 0; j < outputArray.GetLength(0); j++)
{
if (splitString[0] == outputArray[j, 0])
{
for (int k = 1; k < splitString.Length; k++)
{
outputArray[j, k] = splitString[k];
}
}
}
for (int k = 0; k < splitString.Length; k++)
{
outputArray[outputArray.GetLength(0), k] = splitString[k];
}
}
return outputArray;
}
- 问题1:它不起作用
- 问题2:代码很丑
有没有一些简单的方法可以做到这一点?