this is a snippet of a code that i can't figure out how to loop and write to a streamwriter properly:
it outputs something like this: (values are random, it's in ascending order for clarification)
I 1 2 3
I 4 5 6
I 7 8 9
...
I 40 41 42
then the if statement inside getIndices() becomes true
and this time, with this current code, it will print again from the first element of indexList to the end of the next indiceStartGroup element value.
I 1 2 3
I 4 5 6
I 7 8 9
...
I 89 90 91
what i want is to write the next group starting from the next indiceStartGroup element value:
I 40 41 42
I 43 44 45
...
I 89 90 91
any help will be very much appreciated.
sorry if it's not clear enough.
C#:
//for clarity, indexList usually contains thousands of elements
XmlNodeList indexList = xmlFile.SelectNodes("some xpath containing an "array" of values");
//for clarity, indiceStartGroup usually contains few elements, each defining a start position for indexList
XmlNodeList indiceStartGroup = xmlFile.SelectNodes("some xpath containing an "array" of values");
int offset = 3;
//return an array containing each indiceStartGroup element value
private int[] getIndices()
{
int[] value = new int[indiceStartGroup.Count];
for (int i = 0; i < indiceStartGroup.Count; i++)
{
for (int j = 0; j < (indexList.Count); j += offset)
{
if (int.Parse(indiceStartGroup.Item(i).Value) > (int.Parse(indexList.Item(j).Value)))
{
value[i] = j;
}
}
}
return value;
}
private void writeIndices(int counter)
{
int[] indiceGroup = getIndices();
//write indices
for (int ig = 0; ig < indiceGroup[counter]; ig += offset)
{
//StreamWriter, ignore formatting
file.Write("I {0} {1} {2}{3}", (int.Parse(indexList.Item(ig).Value)),
(int.Parse(indexList.Item(ig + 1).Value)), (int.Parse(indexList.Item(ig + 2).Value)),
Environment.NewLine);
}
}
public void OuputFile()
{
//some declarations omitted
for (int i = 0; i < indiceStartGroup.Count; i++) {
//some declarations omitted
writeIndices(i);
}
}
it outputs something like this: (values are random, it's in ascending order for clarification)
I 1 2 3
I 4 5 6
I 7 8 9
...
I 40 41 42
then the if statement inside getIndices() becomes true
and this time, with this current code, it will print again from the first element of indexList to the end of the next indiceStartGroup element value.
I 1 2 3
I 4 5 6
I 7 8 9
...
I 89 90 91
what i want is to write the next group starting from the next indiceStartGroup element value:
I 40 41 42
I 43 44 45
...
I 89 90 91
any help will be very much appreciated.
sorry if it's not clear enough.