I have a list of strings that I'm sending to the method. The method takes the list, iterates over it and removes all the empty strings. In the list I'm sending, there are a total of 7 blank strings but the method only seems to be removing 4 of them.
Here's the method:
public List<string> RemoveWhiteSpace(List<string> rawData)
{
for (int i = 0; i < rawData.Count; i++)
{
if (rawData[i].Length == 0)
{
rawData.RemoveAt(i);
}
}
return rawData;
}
Here's the list itself copied straight from the console:
@0
D=M
@1
D=D-M
@10
D;JGT
@1
D=M
@12
0;JMP
@0
D=M
@2
M=D
@14
0;JMP
This is the output string from the method. It fails to eliminate 3 empty strings. I tested and checked the indices of the strings which aren't being removed, they are indices:4,5 and 6. I also checked the length of these strings and they are in fact 0. I don't understand what the problem is.
@0
D=M
@1
D=D-M
@10
D;JGT
@1
D=M
@12
0;JMP
@0
D=M
@2
M=D
@14
0;JMP